repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
depends
depends-master/src/test/java/depends/extractor/pom/DependencyWithPropertiesTest.java
package depends.extractor.pom; import depends.deptypes.DependencyType; import org.junit.Before; import org.junit.Test; import java.io.IOException; public class DependencyWithPropertiesTest extends MavenParserTest{ @Before public void setUp() { super.init(); } @Test public void should_extract_dep_relation() throws IOException { String[] srcs = new String[] { "./src/test/resources/maven-code-examples/dependencyWithProperties/from.pom", "./src/test/resources/maven-code-examples/dependencyWithProperties/to.pom", }; for (String src:srcs) { PomFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("testgroup.test_1.0_"), DependencyType.PomDependency, "a-dep-group.a-artifact_0.2_"); } @Test public void should_extract_plugin_relation() throws IOException { String[] srcs = new String[] { "./src/test/resources/maven-code-examples/dependencyWithProperties/from.pom", "./src/test/resources/maven-code-examples/dependencyWithProperties/plugin.pom", }; for (String src:srcs) { PomFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("testgroup.test_1.0_"), DependencyType.PomPlugin, "aplugins.aplugin_0.1_"); } }
1,425
30.688889
139
java
depends
depends-master/src/test/java/depends/extractor/pom/DependencyWithPropertiesOfParentTest.java
package depends.extractor.pom; import depends.deptypes.DependencyType; import depends.entity.MultiDeclareEntities; import org.junit.Before; import org.junit.Test; import java.io.IOException; import static org.junit.Assert.assertFalse; public class DependencyWithPropertiesOfParentTest extends MavenParserTest{ @Before public void setUp() { super.init(); } @Test public void should_extract_dep_relation() throws IOException { String[] srcs = new String[] { "./src/test/resources/maven-code-examples/dependencyWithPropertiesOfParent/parent-group/a-parent/1.0/a-parent-1.0.pom", "./src/test/resources/maven-code-examples/dependencyWithPropertiesOfParent/from.pom", "./src/test/resources/maven-code-examples/dependencyWithPropertiesOfParent/to.pom", }; for (String src:srcs) { PomFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); assertFalse(entityRepo.getEntity("parent-group.a-parent_1.0_") instanceof MultiDeclareEntities); this.assertContainsRelation(entityRepo.getEntity("testgroup.test_1.0_"), DependencyType.PomDependency, "a-dep-group.a-artifact_0.2_"); } @Test public void should_extract_plugin_relation() throws IOException { String[] srcs = new String[] { "./src/test/resources/maven-code-examples/dependencyWithPropertiesOfParent/from.pom", "./src/test/resources/maven-code-examples/dependencyWithPropertiesOfParent/parent-group/a-parent/1.0/a-parent-1.0.pom", "./src/test/resources/maven-code-examples/dependencyWithPropertiesOfParent/plugin.pom", }; for (String src:srcs) { PomFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("testgroup.test_1.0_"), DependencyType.PomPlugin, "aplugins.aplugin_0.1_"); } }
1,910
36.470588
139
java
depends
depends-master/src/test/java/depends/extractor/pom/MavenParserTest.java
package depends.extractor.pom; import depends.extractor.ParserTest; import java.util.ArrayList; import java.util.List; public abstract class MavenParserTest extends ParserTest{ public void init() { List<String> includeDir = new ArrayList<>(); includeDir.add("./src/test/resources/maven-code-examples/"); includeDir.add("./src/test/resources/maven-code-examples/dependencyWithPropertiesOfParent"); includeDir.add("./src/test/resources/maven-code-examples/dependencyWithoutVersion"); this.langProcessor = new PomProcessor(); langProcessor.includeDirs = includeDir.toArray(new String[] {}); super.init(); } public PomFileParser createParser() { return (PomFileParser) langProcessor.createFileParser(); } }
733
28.36
94
java
depends
depends-master/src/test/java/depends/extractor/pom/DependencyTest.java
package depends.extractor.pom; import depends.deptypes.DependencyType; import org.junit.Before; import org.junit.Test; import java.io.IOException; public class DependencyTest extends MavenParserTest{ @Before public void setUp() { super.init(); } @Test public void should_extract_dep_relation() throws IOException { String[] srcs = new String[] { "./src/test/resources/maven-code-examples/dependencyRelation/from.pom", "./src/test/resources/maven-code-examples/dependencyRelation/to.pom", }; for (String src:srcs) { PomFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("testgroup.test_1.0_"), DependencyType.PomDependency, "a-dep-group.a-artifact_0.2_"); } @Test public void should_extract_plugin_relation() throws IOException { String[] srcs = new String[] { "./src/test/resources/maven-code-examples/dependencyRelation/from.pom", "./src/test/resources/maven-code-examples/dependencyRelation/plugin.pom", }; for (String src:srcs) { PomFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("testgroup.test_1.0_"), DependencyType.PomPlugin, "aplugins.aplugin_0.1_"); } }
1,387
29.844444
139
java
depends
depends-master/src/test/java/depends/extractor/cpp/GenericTypeTest.java
package depends.extractor.cpp; import static org.junit.Assert.assertNotNull; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.deptypes.DependencyType; import depends.entity.FunctionEntity; public class GenericTypeTest extends CppParserTest { @Before public void setUp() { super.init(); } @Test public void test_templateSpecializationOfStruct() throws IOException { String src = "./src/test/resources/cpp-code-examples/template/TempateStructure.cpp"; CppFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); assertNotNull(entityRepo.getEntity("hash")); } @Test public void test_genericTypesVarParameterReference() throws IOException { String src = "./src/test/resources/cpp-code-examples/template/GenericTypes.cpp"; CppFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("xStack"), DependencyType.PARAMETER, "X"); } @Test public void test_genericTypesExtends() throws IOException { String src = "./src/test/resources/cpp-code-examples/template/GenericTypes.cpp"; CppFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("XStack"), DependencyType.INHERIT, "Stack"); } @Test public void test_GenericTypeEmbededShouldBeIdentified() throws IOException { String src = "./src/test/resources/cpp-code-examples/template/EmbededTemplates.cpp"; CppFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("GenericTypeEmbededTest"), DependencyType.CONTAIN, "MyHashMap"); this.assertContainsRelation(entityRepo.getEntity("GenericTypeEmbededTest.data"), DependencyType.PARAMETER, "MyList"); this.assertContainsRelation(entityRepo.getEntity("GenericTypeEmbededTest.data"), DependencyType.PARAMETER, "MyArray"); } @Test public void test_TemplateWithDots() throws IOException { String src = "./src/test/resources/cpp-code-examples/template/TemplateWithDots.cpp"; CppFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); assertNotNull(entityRepo.getEntity("foo.t2")); } @Test public void test_TemplateInReturn() throws IOException { String src = "./src/test/resources/cpp-code-examples/template/TemplateInReturnValue.cpp"; CppFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); FunctionEntity func = (FunctionEntity) entityRepo.getEntity("get"); this.assertContainsRelation(func, DependencyType.RETURN, "std.tuple_element.type"); this.assertContainsRelation(entityRepo.getEntity("get"), DependencyType.PARAMETER, "Index"); this.assertContainsRelation(entityRepo.getEntity("get"), DependencyType.PARAMETER, "std.tuple"); this.assertContainsRelation(entityRepo.getEntity("get"), DependencyType.PARAMETER, "Domains"); } }
2,936
35.7125
120
java
depends
depends-master/src/test/java/depends/extractor/cpp/TypeDefTest.java
package depends.extractor.cpp; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.deptypes.DependencyType; public class TypeDefTest extends CppParserTest{ @Before public void setUp() { super.init(); } @Test public void test_ref_parameter() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/TypeDefTest.cpp", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("foo"), DependencyType.PARAMETER, "MyInt"); } }
687
22.724138
100
java
depends
depends-master/src/test/java/depends/extractor/cpp/ConstructFunctionReturnValueTest.java
package depends.extractor.cpp; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.extractor.cpp.cdt.CdtCppFileParser; public class ConstructFunctionReturnValueTest extends CppParserTest{ @Before public void setUp() { super.init(); } @Test public void test_constructor() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/ConstructFunction.cpp", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); //assertEquals(1,repo.getEntity("UnderTest").getRelations().size()); } @Test public void test_empty_contains() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/EmptyContains.cpp", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); //assertEquals(1,repo.getEntity("UnderTest").getRelations().size()); } }
1,098
24.55814
76
java
depends
depends-master/src/test/java/depends/extractor/cpp/RelationInSameFileTest.java
package depends.extractor.cpp; import depends.entity.Entity; import depends.entity.FunctionEntityImpl; import depends.entity.FunctionEntityProto; import depends.relations.Relation; import multilang.depends.util.file.FileUtil; import org.junit.Before; import org.junit.Test; import java.io.IOException; import static org.junit.Assert.assertEquals; public class RelationInSameFileTest extends CppParserTest{ @Before public void setUp() { super.init(); } @Test public void should_convert_call_relation_to_impl() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/relation_in_samefile/A.c", "./src/test/resources/cpp-code-examples/relation_in_samefile/B.c" }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(true); Entity bar = entityRepo.getEntity(FileUtil.uniqFilePath(srcs[0])); int matchCount = 0; for (Relation relation:bar.getRelations()) { if (relation.getEntity() instanceof FunctionEntityProto) { matchCount++; } if (relation.getEntity() instanceof FunctionEntityImpl) { matchCount++; } } assertEquals(1, matchCount); } }
1,271
25.5
73
java
depends
depends-master/src/test/java/depends/extractor/cpp/ContainRelationTest.java
package depends.extractor.cpp; import depends.deptypes.DependencyType; import multilang.depends.util.file.FileUtil; import org.junit.Before; import org.junit.Test; import java.io.IOException; import static org.junit.Assert.assertEquals; public class ContainRelationTest extends CppParserTest{ @Before public void setUp() { super.init(); } @Test public void same_file_contains() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/relationContain/SameFileContainTest.hpp", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); assertEquals(1, entityRepo.getEntity("UnderTest").getRelations().size()); } @Test public void included_file_contains() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/relationContain/ContainTest.h", "./src/test/resources/cpp-code-examples/relationContain/BeContained.h", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(FileUtil.uniqFilePath(src)); } resolveAllBindings(); assertEquals(2, entityRepo.getEntity("UnderTest").getRelations().size()); } @Test public void precedence_declaration_file_contains() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/relationContain/PrecedenceDeclaration.hpp", "./src/test/resources/cpp-code-examples/relationContain/BeContained.h", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("UnderTest"), DependencyType.CONTAIN, "Member"); } @Test public void precedence_used_in_impl_file() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/relationContain/PrecedenceDeclaration.cpp", "./src/test/resources/cpp-code-examples/relationContain/PrecedenceDeclaration.hpp", "./src/test/resources/cpp-code-examples/relationContain/BeContained.h", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); } }
2,386
29.602564
102
java
depends
depends-master/src/test/java/depends/extractor/cpp/ImplementRelationTest.java
package depends.extractor.cpp; import depends.deptypes.DependencyType; import depends.entity.Entity; import depends.entity.FunctionEntityImpl; import depends.entity.MultiDeclareEntities; import org.junit.Before; import org.junit.Test; import java.io.IOException; import java.util.List; import java.util.stream.Collectors; public class ImplementRelationTest extends CppParserTest{ @Before public void setUp() { super.init(); } @Test public void should_detect_implements_from_source_to_header() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/relationImplements/A.cpp", "./src/test/resources/cpp-code-examples/relationImplements/A.h", }; for (String src:srcs) { CppFileParser parser =createParser(); parser.parse(src); } resolveAllBindings(); MultiDeclareEntities multiDeclare = (MultiDeclareEntities)( entityRepo.getEntity("foo")); List<Entity> f = multiDeclare.getEntities().stream().filter(item->item.getClass().equals(FunctionEntityImpl.class)).collect(Collectors.toList()); this.assertContainsRelation(f.get(0),DependencyType.IMPLEMENT,"foo"); } }
1,200
32.361111
150
java
depends
depends-master/src/test/java/depends/extractor/cpp/RelationToImplementationTest.java
package depends.extractor.cpp; import depends.entity.Entity; import depends.entity.FunctionEntityImpl; import depends.entity.FunctionEntityProto; import depends.entity.VarEntity; import depends.relations.Relation; import org.junit.Before; import org.junit.Test; import java.io.IOException; import static org.junit.Assert.assertEquals; public class RelationToImplementationTest extends CppParserTest{ @Before public void setUp() { super.init(); } @Test public void should_convert_call_relation_to_impl() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/relation_to_impl/A.h", "./src/test/resources/cpp-code-examples/relation_to_impl/B.c", "./src/test/resources/cpp-code-examples/relation_to_impl/A.c", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(true); Entity bar = entityRepo.getEntity("bar"); int matchCount = 0; for (Relation relation:bar.getRelations()) { if (relation.getEntity() instanceof FunctionEntityProto) { matchCount++; } if (relation.getEntity() instanceof FunctionEntityImpl) { matchCount++; } } assertEquals(2, matchCount); } @Test public void should_convert_var_relation_to_impl() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/relation_to_impl/A.h", "./src/test/resources/cpp-code-examples/relation_to_impl/B.c", "./src/test/resources/cpp-code-examples/relation_to_impl/A.c", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(true); Entity bar = entityRepo.getEntity("baz"); int matchCount = 0; for (Relation relation:bar.getRelations()) { if (relation.getEntity() instanceof VarEntity) { matchCount++; } } assertEquals(2, matchCount); } @Test public void should_not_count_local_var() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/relation_to_impl/A.h", "./src/test/resources/cpp-code-examples/relation_to_impl/B.c", "./src/test/resources/cpp-code-examples/relation_to_impl/A.c", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(true); Entity bar = entityRepo.getEntity("qux"); int matchCount = 0; for (Relation relation:bar.getRelations()) { if (relation.getEntity() instanceof VarEntity) { matchCount++; } } assertEquals(1, matchCount); } }
2,757
28.340426
72
java
depends
depends-master/src/test/java/depends/extractor/cpp/ParseErrorTest.java
package depends.extractor.cpp; import depends.extractor.cpp.cdt.CdtCppFileParser; import org.junit.Before; import org.junit.Test; import java.io.IOException; import java.util.HashMap; import java.util.Map; public class ParseErrorTest extends CppParserTest{ @Before public void setUp() { super.init(); } @Test public void full_qualified_names_should_be_resolved() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/parseError/error1.c", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); } @Test public void macro_definition() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/parseError/macro.c", }; for (String src:srcs) { CdtCppFileParser parser = (CdtCppFileParser)createParser(); Map<String, String> macroMap = new HashMap<>(); macroMap.put("AP_DECLARE(x)","x"); parser.parse(src,macroMap); } resolveAllBindings(); } }
1,077
22.434783
75
java
depends
depends-master/src/test/java/depends/extractor/cpp/MacroTest.java
package depends.extractor.cpp; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.entity.MultiDeclareEntities; public class MacroTest extends CppParserTest{ @Before public void setUp() { super.init(); } @Test public void macro_should_be_expanded() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/macros/Macro.cpp", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); assertNotNull(this.entityRepo.getEntity("Macro")); } @Test public void header_file_can_only_be_count_once() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/macros/Macro.cpp", "./src/test/resources/cpp-code-examples/macros/Macro2.cpp", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); assertFalse(entityRepo.getEntity("foo") instanceof MultiDeclareEntities); } @Test public void intermediate_file_include_should_work() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/macros/Macro3.cpp", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); assertNotNull(entityRepo.getEntity("Macro3.bar")); } }
1,742
23.9
81
java
depends
depends-master/src/test/java/depends/extractor/cpp/extendsTest.java
package depends.extractor.cpp; import static org.junit.Assert.assertEquals; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.entity.Entity; public class extendsTest extends CppParserTest{ @Before public void setUp() { super.init(); } @Test public void full_qualified_names_should_be_resolved() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/inheritTest.hpp", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); Entity e = entityRepo.getEntity("B"); assertEquals(2,e.getRelations().size()); } }
737
21.363636
75
java
depends
depends-master/src/test/java/depends/extractor/cpp/UsingTest.java
package depends.extractor.cpp; import depends.deptypes.DependencyType; import depends.entity.Entity; import depends.entity.TypeEntity; import org.junit.Before; import org.junit.Test; import java.io.IOException; public class UsingTest extends CppParserTest{ @Before public void setUp() { super.init(); } @Test public void full_qualified_names_should_be_resolved() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/UsingTest.cpp", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); Entity e = entityRepo.getEntity("foo"); this.assertContainsRelation(e, DependencyType.RETURN, TypeEntity.buildInType.getQualifiedName()); this.assertContainsRelation(e, DependencyType.CONTAIN, "A.C"); this.assertContainsRelation(e, DependencyType.CONTAIN, "B.X"); } @Test public void suffix_names_should_be_resolved() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/UsingTest.cpp", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); Entity e = entityRepo.getEntity("bar"); this.assertContainsRelation(e, DependencyType.RETURN, TypeEntity.buildInType.getQualifiedName()); this.assertContainsRelation(e, DependencyType.CONTAIN, "A.C"); this.assertContainsRelation(e, DependencyType.CONTAIN, "B.X"); } }
1,596
29.711538
105
java
depends
depends-master/src/test/java/depends/extractor/cpp/AliasTest.java
package depends.extractor.cpp; import depends.deptypes.DependencyType; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import java.io.IOException; import static org.junit.Assert.fail; public class AliasTest extends CppParserTest{ @Before public void setUp() { super.init(); } @Test public void test_genericTypes() throws IOException { String src = "./src/test/resources/cpp-code-examples/Alias.cpp"; CppFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("bar"), DependencyType.CALL, "F.foo"); } @Test public void test_refer_to_alias_type_should_work() throws IOException { String src = "./src/test/resources/cpp-code-examples/AliasType.cpp"; CppFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("C"), DependencyType.INHERIT, "A"); } @Test public void test_multi_declares_should_only_count_actual_referred() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/MultiDeclareRef.h", "./src/test/resources/cpp-code-examples/MultiDeclareRef.cpp", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("bar"), DependencyType.CALL, "foo"); } @Ignore public void test_header_files_not_contains_include_should_be_resolved() { /*非规范的include形式,和include顺序有关,例如 A header file contains class T A.hpp // the file use T, but not include T, because it always use after previous header file typedef T1 T; * */ //TODO: fail("to be implemented"); } }
1,862
28.571429
97
java
depends
depends-master/src/test/java/depends/extractor/cpp/DuplicateDeclarationTest.java
package depends.extractor.cpp; import depends.deptypes.DependencyType; import depends.entity.Entity; import org.junit.Before; import org.junit.Test; import java.io.IOException; public class DuplicateDeclarationTest extends CppParserTest { @Before public void setUp() { super.init(); } @Test public void duplication_declaration_should_be_resolved() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/DuplicationDeclarationCouldBeResolved.cpp", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); Entity e = entityRepo.getEntity("X.invoke"); this.assertContainsRelation(e, DependencyType.CONTAIN,"DupClass"); this.assertContainsRelation(e, DependencyType.CALL,"DupClass"); this.assertContainsRelation(e, DependencyType.CREATE,"DupClass"); this.assertContainsRelation(e, DependencyType.CALL,"DupClass.foo"); } }
1,049
26.631579
92
java
depends
depends-master/src/test/java/depends/extractor/cpp/CppParameterParserTest.java
package depends.extractor.cpp; import static org.junit.Assert.assertEquals; import java.io.IOException; import org.junit.Before; import org.junit.Test; public class CppParameterParserTest extends CppParserTest{ @Before public void setUp() { super.init(); } @Test public void test_parameter() throws IOException { String src = "./src/test/resources/cpp-code-examples/FunctionParameters.cpp"; CppFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); assertEquals(4, entityRepo.getEntity("FunctionParameters.function_with_parameters_same_type").getRelations().size()); } }
653
25.16
125
java
depends
depends-master/src/test/java/depends/extractor/cpp/CppParserTest.java
package depends.extractor.cpp; import depends.extractor.ParserTest; import depends.extractor.cpp.cdt.CdtCppFileParser; import depends.extractor.cpp.cdt.PreprocessorHandler; import java.util.ArrayList; public abstract class CppParserTest extends ParserTest{ protected PreprocessorHandler preprocessorHandler; private MacroRepo macroRepo; public void init() { langProcessor = new CppProcessor(); preprocessorHandler = new PreprocessorHandler("./src/test/resources/cpp-code-examples/",new ArrayList<>()); super.init(); macroRepo = new MacroEhcacheRepo(entityRepo); } public CppFileParser createParser() { return new CdtCppFileParser(entityRepo, preprocessorHandler, bindingResolver,macroRepo ); } }
731
29.5
112
java
depends
depends-master/src/test/java/depends/extractor/cpp/IncludeRelationTest.java
package depends.extractor.cpp; import static org.junit.Assert.assertEquals; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.junit.Before; import org.junit.Test; import depends.deptypes.DependencyType; import depends.entity.AliasEntity; import multilang.depends.util.file.FileUtil; public class IncludeRelationTest extends CppParserTest{ @Before public void setUp() { super.init(); } @Test public void test_includefiles_should_be_imported_relations() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/includesTest/EntryFile.cpp", "./src/test/resources/cpp-code-examples/includesTest/LocalHeader.h", "./src/test/resources/cpp-code-examples/includesTest/IndirectIncluded.h", "./src/test/resources/cpp-code-examples/includesTest/RelativeInclude.h", "./src/test/resources/cpp-code-examples/includesTest/path/Header.h", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); File f = new File(srcs[0]); assertEquals(3, entityRepo.getEntity(f.getCanonicalPath()).getRelations().size()); } @Test public void test_could_found_files_in_include_path() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/includesTest/EntryFileIncludePathTest.cpp", "./src/test/resources/cpp-code-examples/includesTest/path/HeadersWithoutPath.h", }; List<String> includePaths = new ArrayList<>(); includePaths.add("./src/test/resources/cpp-code-examples/includesTest/path/"); for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); File f = new File(srcs[0]); assertEquals(1, entityRepo.getEntity(f.getCanonicalPath()).getRelations().size()); } @Test public void test_type_t_should_be_treat_as_structure() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/typedeftest2.cpp", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); assertEquals("abc",((AliasEntity) entityRepo.getEntity("abc_t")).getOriginType().getRawName().uniqName()); } @Test public void test_call_should_only_in_relations_with_include() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/includeTest2/f0.cpp", "./src/test/resources/cpp-code-examples/includeTest2/f_with_include.cpp", "./src/test/resources/cpp-code-examples/includeTest2/f_without_include.cpp", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); this.assertContainsRelation(this.entityRepo.getEntity("foo"), DependencyType.CALL, "bar"); this.assertNotContainsRelation(this.entityRepo.getEntity("foo2"), DependencyType.CALL, "bar"); } @Test public void should_find_include_relation_in_conditional_macro_block() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/includeTest3/inc_macro_test.c", "./src/test/resources/cpp-code-examples/includeTest3/fx.h", "./src/test/resources/cpp-code-examples/includeTest3/fy.h", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); this.assertContainsRelation(this.entityRepo.getEntity(FileUtil.uniqFilePath(srcs[0])), DependencyType.IMPORT, FileUtil.uniqFilePath(srcs[1])); this.assertContainsRelation(this.entityRepo.getEntity(FileUtil.uniqFilePath(srcs[0])), DependencyType.IMPORT, FileUtil.uniqFilePath(srcs[2])); } }
3,966
35.063636
147
java
depends
depends-master/src/test/java/depends/extractor/cpp/MacroRelationTest.java
package depends.extractor.cpp; import depends.deptypes.DependencyType; import depends.entity.Entity; import depends.entity.TypeEntity; import org.junit.Before; import org.junit.Test; import java.io.IOException; public class MacroRelationTest extends CppParserTest{ @Before public void setUp() { super.init(); } @Test public void macro_var_relation_in_seperate_file() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/MacroRelationTestInSeperateFile.h", "./src/test/resources/cpp-code-examples/MacroRelationTestInSeperateFile.cpp", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); Entity e = entityRepo.getEntity("foo"); this.assertContainsRelation(e, DependencyType.RETURN, TypeEntity.buildInType.getQualifiedName()); this.assertContainsRelation(e, DependencyType.CONTAIN, TypeEntity.buildInType.getQualifiedName()); } }
1,028
28.4
103
java
depends
depends-master/src/test/java/depends/extractor/cpp/CppExpressionTest.java
package depends.extractor.cpp; import depends.deptypes.DependencyType; import depends.entity.Entity; import org.junit.Before; import org.junit.Test; import java.io.IOException; import static org.junit.Assert.assertEquals; public class CppExpressionTest extends CppParserTest{ @Before public void setUp() { super.init(); } @Test public void test_expressions() throws IOException { String src = "./src/test/resources/cpp-code-examples/Expressions.cpp"; CppFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); Entity e = entityRepo.getEntity("foo"); this.assertContainsRelation(e, DependencyType.PARAMETER,"ClassA"); this.assertContainsRelation(e, DependencyType.CAST,"ClassA"); this.assertContainsRelation(e, DependencyType.CALL,"ClassA"); this.assertContainsRelation(e, DependencyType.CREATE,"ClassA"); this.assertContainsRelation(e, DependencyType.USE,"ClassA"); this.assertContainsRelation(e, DependencyType.USE,"foo.a2"); this.assertContainsRelation(e, DependencyType.USE,"foo.a3"); this.assertContainsRelation(e, DependencyType.USE,"foo.a"); this.assertContainsRelation(e, DependencyType.CONTAIN,"ClassA"); } @Test public void test_should_not_count_expr_duplicated() throws IOException { String src = "./src/test/resources/cpp-code-examples/DupExpressions.cpp"; CppFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); Entity e = entityRepo.getEntity("foo"); assertEquals(4,e.getRelations().size()); } }
1,651
35.711111
81
java
depends
depends-master/src/test/java/depends/extractor/cpp/ForwardDeclareTest.java
package depends.extractor.cpp; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.generator.FileDependencyGenerator; public class ForwardDeclareTest extends CppParserTest{ @Before public void setUp() { super.init(); } @Test public void should_slove_forward_declare_in_cpp() throws IOException { String[] srcs = new String[] { "./src/test/resources/cpp-code-examples/forwardDeclare/App.cpp", "./src/test/resources/cpp-code-examples/forwardDeclare/Mutex.h", "./src/test/resources/cpp-code-examples/forwardDeclare/App.h", }; for (String src:srcs) { CppFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); //TODO: to be complete } }
799
24
71
java
depends
depends-master/src/test/java/depends/extractor/python/PythonParameterTypeDedudceTest.java
package depends.extractor.python; import depends.entity.CandidateTypes; import depends.entity.FunctionEntity; import depends.entity.TypeEntity; import depends.entity.VarEntity; import depends.extractor.FileParser; import edu.emory.mathcs.backport.java.util.Arrays; import org.junit.Before; import org.junit.Test; import java.io.IOException; import java.util.List; import java.util.stream.Collectors; import static org.junit.Assert.*; public class PythonParameterTypeDedudceTest extends PythonParserTest { @Before public void setUp() { super.init(); } @Test public void test_deduce_type_of_parameter() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/deducetype_parameter.py", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); String name = withPackageName(srcs[0],"test"); FunctionEntity function = (FunctionEntity)( entityRepo.getEntity(name)); VarEntity var = function.lookupVarLocally("t1"); TypeEntity type = var.getType(); assertTrue(type instanceof CandidateTypes); assertEquals(2,((CandidateTypes)type).getCandidateTypes().size()); } @Test public void test_deduce_type_of_builtIn() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/deducetype_builtin.py", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); String name = withPackageName(srcs[0],"test"); FunctionEntity function = (FunctionEntity)( entityRepo.getEntity(name)); VarEntity var = function.lookupVarLocally("t1"); TypeEntity type = var.getType(); assertTrue(type == null); } @Test public void test_deduce_type_of_builtIn_cannot_override() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/deducetype_builtin.py", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); String name = withPackageName(srcs[0],"test2"); FunctionEntity function = (FunctionEntity)( entityRepo.getEntity(name)); VarEntity var = function.lookupVarLocally("t1"); TypeEntity type = var.getType(); assertTrue(type instanceof CandidateTypes); assertEquals(1,((CandidateTypes)type).getCandidateTypes().size()); } @Test public void test_deduce_type_of_non_param_var() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/deducetype_nonparam.py", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); String name = withPackageName(srcs[0],"test"); FunctionEntity function = (FunctionEntity)( entityRepo.getEntity(name)); VarEntity var = function.lookupVarLocally("t2"); TypeEntity type = var.getType(); assertTrue(type instanceof CandidateTypes); assertEquals(1,((CandidateTypes)type).getCandidateTypes().size()); } @Test public void test_expression_with_duck_type_should_introduce_possibile_relation() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/expression_reload_issue_test.py", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); String name = withPackageName(srcs[0],"test_expression"); FunctionEntity function = (FunctionEntity)( entityRepo.getEntity(name)); List<Boolean> result = function.getRelations().stream().map(r -> r.possible()).collect(Collectors.toList()); List<Boolean> expected = Arrays.asList(new Boolean[]{false,false,true,true,true,false, false, true, true,false}); assertArrayEquals(expected.toArray(),result.toArray()); } }
3,997
31.504065
115
java
depends
depends-master/src/test/java/depends/extractor/python/PythonObjectCreationTest.java
package depends.extractor.python; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.deptypes.DependencyType; import depends.entity.FunctionEntity; import depends.extractor.python.union.PythonFileParser; public class PythonObjectCreationTest extends PythonParserTest { @Before public void setUp() { super.init(); } @Test public void could_parse_object_creation() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/object_creation.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity func = (FunctionEntity) entityRepo.getEntity(withPackageName(srcs[0],"foo")); this.assertContainsRelation(func, DependencyType.CREATE, withPackageName(srcs[0],"Bar")); } }
908
24.971429
97
java
depends
depends-master/src/test/java/depends/extractor/python/PythonFuncCallTest.java
package depends.extractor.python; import depends.deptypes.DependencyType; import depends.entity.FunctionEntity; import depends.extractor.python.union.PythonFileParser; import org.junit.Before; import org.junit.Test; import java.io.IOException; public class PythonFuncCallTest extends PythonParserTest { @Before public void setUp() { super.init(); } @Test public void could_parse_func_call() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/func_call.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity func = (FunctionEntity) entityRepo.getEntity(withPackageName(srcs[0],"foo")); this.assertContainsRelation(func, DependencyType.CALL, withPackageName(srcs[0],"bar")); } @Test public void could_parse_func_call_of_member() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/func_call.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity func = (FunctionEntity) entityRepo.getEntity(withPackageName(srcs[0],"baz")); this.assertContainsRelation(func, DependencyType.CALL, withPackageName(srcs[0],"A.foo")); } @Test public void could_parse_func_call_of_multi_dots() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/func_call_multi_dots.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity func = (FunctionEntity) entityRepo.getEntity(withPackageName(srcs[0],"func_call_multi_dots","C.test")); this.assertContainsRelation(func, DependencyType.CALL, withPackageName(srcs[0],"func_call_multi_dots","A.fooA")); this.assertContainsRelation(func, DependencyType.CALL, withPackageName(srcs[0],"func_call_multi_dots","B.fooB")); this.assertContainsRelation(func, DependencyType.CALL, withPackageName(srcs[0],"func_call_multi_dots","C.fooC")); } }
2,241
32.969697
123
java
depends
depends-master/src/test/java/depends/extractor/python/SelfShouldBeThisTypeTest.java
package depends.extractor.python; import depends.entity.FunctionEntity; import depends.entity.TypeEntity; import depends.entity.VarEntity; import depends.extractor.FileParser; import org.junit.Before; import org.junit.Test; import java.io.IOException; import static org.junit.Assert.assertTrue; public class SelfShouldBeThisTypeTest extends PythonParserTest { @Before public void setUp() { super.init(); } @Test public void test_deduce_type_of_return() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/self_should_be_this_type.py", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity function = (FunctionEntity)(entityRepo.getEntity(withPackageName(srcs[0],"A.foo"))); VarEntity var = function.lookupVarLocally("self"); TypeEntity type = var.getType(); assertTrue(type.getQualifiedName().equals(withPackageName(srcs[0],"A"))); } }
1,037
26.315789
104
java
depends
depends-master/src/test/java/depends/extractor/python/PythonObjectThrowReturn.java
package depends.extractor.python; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.deptypes.DependencyType; import depends.entity.FunctionEntity; import depends.extractor.python.union.PythonFileParser; public class PythonObjectThrowReturn extends PythonParserTest { @Before public void setUp() { super.init(); } @Test public void could_parse_throws() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/throw_return.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity func = (FunctionEntity) entityRepo.getEntity(withPackageName(srcs[0],"t1")); this.assertContainsRelation(func, DependencyType.THROW, withPackageName(srcs[0],"Bar")); } @Test public void could_parse_return() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/throw_return.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity func = (FunctionEntity) entityRepo.getEntity(withPackageName(srcs[0],"t2")); this.assertContainsRelation(func, DependencyType.RETURN, withPackageName(srcs[0],"Bar")); } }
1,411
26.153846
96
java
depends
depends-master/src/test/java/depends/extractor/python/PythonParserTest.java
package depends.extractor.python; import depends.extractor.FileParser; import depends.extractor.ParserCreator; import depends.extractor.ParserTest; import depends.extractor.python.union.PythonFileParser; import depends.extractor.python.union.PythonProcessor; import multilang.depends.util.file.FileUtil; import java.util.ArrayList; import java.util.List; public abstract class PythonParserTest extends ParserTest implements ParserCreator { public void init() { List<String> includeDir = new ArrayList<>(); includeDir.add("./src/test/resources/python-code-examples/"); this.langProcessor = new PythonProcessor(); langProcessor.includeDirs = includeDir.toArray(new String[] {}); super.init(true); } public PythonFileParser createParser() { return (PythonFileParser)createFileParser(); } @Override public FileParser createFileParser() { return langProcessor.createFileParser(); } protected String withPackageName(String theFile,String entityName) { String uniqName = FileUtil.uniqFilePath(theFile); return FileUtil.getLocatedDir(uniqName)+"."+FileUtil.getShortFileName(uniqName).replace(".py","")+"."+entityName; } protected String withPackageName(String theFile, String moduleName, String entityName) { String uniqName = FileUtil.uniqFilePath(theFile); return FileUtil.getLocatedDir(uniqName)+"."+moduleName+"."+entityName; } protected String withPackageName2(String theFile, String entityName) { String uniqName = FileUtil.uniqFilePath(theFile); return FileUtil.getLocatedDir(uniqName)+"."+entityName; } }
1,561
31.541667
115
java
depends
depends-master/src/test/java/depends/extractor/python/ShouldGetRelationInSamePackageTest.java
package depends.extractor.python; import depends.deptypes.DependencyType; import depends.entity.FunctionEntity; import depends.extractor.FileParser; import org.junit.Before; import org.junit.Test; import java.io.IOException; public class ShouldGetRelationInSamePackageTest extends PythonParserTest { @Before public void setUp() { super.init(); } @Test public void test_relations_of_same_package() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/relations_of_same_package/a.py", "./src/test/resources/python-code-examples/relations_of_same_package/b.py" }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity function = (FunctionEntity)(entityRepo.getEntity(withPackageName(srcs[0],"b","bar"))); this.assertContainsRelation(function, DependencyType.CALL, withPackageName(srcs[0],"a","foo")); } }
995
28.294118
106
java
depends
depends-master/src/test/java/depends/extractor/python/PythonImportTest.java
package depends.extractor.python; import depends.deptypes.DependencyType; import depends.entity.Entity; import depends.entity.FileEntity; import depends.entity.FunctionEntity; import depends.extractor.python.union.PythonFileParser; import multilang.depends.util.file.FileUtil; import org.junit.Before; import org.junit.Test; import java.io.IOException; public class PythonImportTest extends PythonParserTest { @Before public void setUp() { super.init(); } @Test public void should_parse_module_in_same_package() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/imported_a.py", "./src/test/resources/python-code-examples/importing.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); Entity file = entityRepo.getEntity(FileUtil.uniqFilePath(srcs[1])); this.assertContainsRelation(file, DependencyType.IMPORT,FileUtil.uniqFilePath(srcs[0])); } @Test public void should_parse_module_in_same_package_order_robust() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/importing.py", "./src/test/resources/python-code-examples/imported_a.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); Entity file = entityRepo.getEntity(FileUtil.uniqFilePath(srcs[0])); this.assertContainsRelation(file, DependencyType.IMPORT,FileUtil.uniqFilePath(srcs[1])); this.assertContainsRelation(file, DependencyType.CALL,withPackageName(srcs[0],"imported_a","foo")); } @Test public void should_parse_module_in_same_package_with_alias() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/importing_with_alias.py", "./src/test/resources/python-code-examples/imported_a.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); Entity file = entityRepo.getEntity(FileUtil.uniqFilePath(srcs[0])); this.assertContainsRelation(file, DependencyType.IMPORT,FileUtil.uniqFilePath(srcs[1])); this.assertContainsRelation(file, DependencyType.CALL,withPackageName(srcs[0], "imported_a", "foo")); } @Test public void should_parse_module_in_from_importing() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/from_importing.py", "./src/test/resources/python-code-examples/imported_a.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); Entity file = entityRepo.getEntity(FileUtil.uniqFilePath(srcs[0])); this.assertContainsRelation(file, DependencyType.CALL,withPackageName(srcs[0], "imported_a","foo")); this.assertContainsRelation(file, DependencyType.IMPORT,FileUtil.uniqFilePath(srcs[1])); } @Test public void should_parse_module_in_from_importing_star() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/from_importing_star.py", "./src/test/resources/python-code-examples/imported_a.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); Entity file = entityRepo.getEntity(FileUtil.uniqFilePath(srcs[0])); this.assertContainsRelation(file, DependencyType.CALL,withPackageName(srcs[0],"imported_a","foo")); this.assertContainsRelation(file, DependencyType.IMPORT,FileUtil.uniqFilePath(srcs[1])); } @Test public void should_parse_import_with_multi_dots() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/from_importing_multidot.py", "./src/test/resources/python-code-examples/pkg/imported.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); Entity file = entityRepo.getEntity(FileUtil.uniqFilePath(srcs[0])); this.assertContainsRelation(file, DependencyType.IMPORT,FileUtil.uniqFilePath(srcs[1])); this.assertContainsRelation(file, DependencyType.CALL,withPackageName(srcs[1],"foo")); } @Test public void should_parse_import_with_prefix_dots() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/import_with_dir/importing.py", "./src/test/resources/python-code-examples/import_with_dir/imported_a.py", "./src/test/resources/python-code-examples/import_with_dir/subdir/importing.py", "./src/test/resources/python-code-examples/import_with_dir/subdir/importing2.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity(FileUtil.uniqFilePath(srcs[0])), DependencyType.IMPORT,FileUtil.uniqFilePath(srcs[1])); this.assertContainsRelation(entityRepo.getEntity(FileUtil.uniqFilePath(srcs[2])), DependencyType.IMPORT,FileUtil.uniqFilePath(srcs[1])); this.assertContainsRelation(entityRepo.getEntity(FileUtil.uniqFilePath(srcs[3])), DependencyType.IMPORT,FileUtil.uniqFilePath(srcs[1])); } @Test public void should_parse_import_with_prefix_dots2() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/import_with_dir/subdir/importing2.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); } @Test public void should_import_from_package__init__file() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/import_from_init/importing.py", "./src/test/resources/python-code-examples/import_from_init/pkg/__init__.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity(FileUtil.uniqFilePath(srcs[0])), DependencyType.IMPORT,FileUtil.uniqFilePath(srcs[1])); } @Test public void should_not_bypass_import_in_same_dir() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/import_of_same_dir/pkg/importing.py", "./src/test/resources/python-code-examples/import_of_same_dir/pkg/a.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity(FileUtil.uniqFilePath(srcs[0])), DependencyType.IMPORT,FileUtil.uniqFilePath(srcs[1])); } @Test public void should_resolve_symbols_of_imported_in_same_dir() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/import_of_same_dir/pkg/importing.py", "./src/test/resources/python-code-examples/import_of_same_dir/pkg/a.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity func = (FunctionEntity) entityRepo.getEntity(withPackageName(srcs[0],"test")); this.assertContainsRelation(func, DependencyType.CALL, withPackageName(srcs[1],"foo")); } @Test public void should_resolve_symbols_of_ducktyping() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/duck_typing/forest.py", "./src/test/resources/python-code-examples/duck_typing/animals.py", "./src/test/resources/python-code-examples/duck_typing/controller.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); Entity func = entityRepo.getEntity(withPackageName(srcs[1], "forest","in_the_forest")); this.assertContainsRelation(func, DependencyType.CALL, withPackageName(srcs[1],"Duck.quack")); this.assertContainsRelation(func, DependencyType.CALL, withPackageName(srcs[1],"Doge.quack")); this.assertContainsRelation(func, DependencyType.CALL, withPackageName(srcs[1],"Bird.quack")); } @Test public void should_resolve_symbols_of_ducktyping2() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/duck_typing/animals.py", "./src/test/resources/python-code-examples/duck_typing/forest.py", "./src/test/resources/python-code-examples/duck_typing/controller.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); Entity func = entityRepo.getEntity(withPackageName(srcs[1], "forest","in_the_forest")); this.assertContainsRelation(func, DependencyType.CALL, withPackageName(srcs[0],"Duck.quack")); this.assertContainsRelation(func, DependencyType.CALL, withPackageName(srcs[0],"Bird.quack")); this.assertContainsRelation(func, DependencyType.CALL, withPackageName(srcs[0],"Doge.quack")); } @Test public void should_resolve_imported_symbols() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/import_from_init/use_imported.py", "./src/test/resources/python-code-examples/import_from_init/pkg/__init__.py", "./src/test/resources/python-code-examples/import_from_init/pkg/core.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity func = (FunctionEntity) entityRepo.getEntity(withPackageName(srcs[0],"use_imported", "bar")); this.assertContainsRelation(func, DependencyType.CALL, withPackageName2(srcs[2],"C")); } @Test public void should_resolve_imported_vars() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/import_from_var/use_imported.py", "./src/test/resources/python-code-examples/import_from_var/pkg/core.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); FileEntity f = (FileEntity) entityRepo.getEntity(FileUtil.uniqFilePath(srcs[0])); this.assertContainsRelation(f, DependencyType.CALL, withPackageName(srcs[1],"Core.foo")); } }
10,789
37.262411
138
java
depends
depends-master/src/test/java/depends/extractor/python/PythonClassTest.java
package depends.extractor.python; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.deptypes.DependencyType; import depends.entity.TypeEntity; import depends.extractor.python.union.PythonFileParser; public class PythonClassTest extends PythonParserTest { @Before public void setUp() { super.init(); } @Test public void should_parse_class() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/class.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); assertNotNull(entityRepo.getEntity(withPackageName(srcs[0],"Foo"))); } @Test public void should_parse_method_of_class() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/class.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); TypeEntity type = (TypeEntity) entityRepo.getEntity(withPackageName(srcs[0],"Foo")); assertEquals(2,type.getFunctions().size()); } @Test public void should_parse_baseclass_of_class() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/class.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); TypeEntity type = (TypeEntity) entityRepo.getEntity(withPackageName(srcs[0],"Bar")); this.assertContainsRelation(type, DependencyType.INHERIT, withPackageName(srcs[0],"Foo")); } }
1,835
26.402985
95
java
depends
depends-master/src/test/java/depends/extractor/python/PythonDecoratorTest.java
package depends.extractor.python; import static org.junit.Assert.assertEquals; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.deptypes.DependencyType; import depends.entity.FunctionEntity; import depends.extractor.python.union.PythonFileParser; public class PythonDecoratorTest extends PythonParserTest { @Before public void setUp() { super.init(); } @Test public void could_parse_decorated() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/decorated.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity func = (FunctionEntity) entityRepo.getEntity(withPackageName(srcs[0],"foo")); this.assertContainsRelation(func, DependencyType.ANNOTATION , withPackageName(srcs[0],"our_decorator")); assertEquals(1,func.getResolvedAnnotations().size()); } }
1,008
25.552632
106
java
depends
depends-master/src/test/java/depends/extractor/python/PythonClassAssignmentTest.java
package depends.extractor.python; import depends.entity.AliasEntity; import depends.entity.Entity; import depends.extractor.python.union.PythonFileParser; import org.junit.Before; import org.junit.Test; import java.io.IOException; import static org.junit.Assert.assertTrue; public class PythonClassAssignmentTest extends PythonParserTest { @Before public void setUp() { super.init(); } @Test public void class_assignment_should_be_treat_as_alias() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/class_assignment.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); Entity classB = entityRepo.getEntity(withPackageName(srcs[0],"class_assignment","ClassB")); assertTrue(classB instanceof AliasEntity); } }
904
25.617647
93
java
depends
depends-master/src/test/java/depends/extractor/python/PythonFunctionTest.java
package depends.extractor.python; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.entity.FunctionEntity; import depends.extractor.python.union.PythonFileParser; public class PythonFunctionTest extends PythonParserTest { @Before public void setUp() { super.init(); } @Test public void should_parse_methods() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/func.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); assertNotNull(entityRepo.getEntity(withPackageName(srcs[0],"foo"))); } @Test public void should_parse_method_parameters() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/func.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity func = (FunctionEntity) entityRepo.getEntity(withPackageName(srcs[0],"foo")); assertEquals(2,func.getParameters().size()); } }
1,300
24.019231
97
java
depends
depends-master/src/test/java/depends/extractor/python/ImportWithSameNameTest.java
package depends.extractor.python; import depends.entity.VarEntity; import depends.extractor.python.union.PythonFileParser; import org.junit.Before; import org.junit.Test; import java.io.IOException; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; public class ImportWithSameNameTest extends PythonParserTest { @Before public void setUp() { super.init(); } @Test public void same_name_in_different_file_should_be_treat_as_two_vars() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/import_with_same_name/b.py", "./src/test/resources/python-code-examples/import_with_same_name/pkg/a.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); VarEntity foo_a = (VarEntity) entityRepo.getEntity(withPackageName(srcs[1],"a","foo")); assertNotNull(foo_a); VarEntity foo_b = (VarEntity) entityRepo.getEntity(withPackageName(srcs[0],"b","foo")); assertNotNull(foo_b); assertFalse(foo_a.equals(foo_b)); } @Test public void same_name_in_different_file_should_be_treat_as_two_vars_diff_order() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/import_with_same_name/pkg/a.py", "./src/test/resources/python-code-examples/import_with_same_name/b.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); VarEntity foo_a = (VarEntity) entityRepo.getEntity(withPackageName(srcs[0],"a","foo")); assertNotNull(foo_a); VarEntity foo_b = (VarEntity) entityRepo.getEntity(withPackageName(srcs[1],"b","foo")); assertNotNull(foo_b); assertFalse(foo_a.equals(foo_b)); } }
1,827
31.070175
102
java
depends
depends-master/src/test/java/depends/extractor/python/PythonGlobalVarTest.java
package depends.extractor.python; import depends.deptypes.DependencyType; import depends.entity.Entity; import depends.extractor.python.union.PythonFileParser; import org.junit.Before; import org.junit.Test; import java.io.IOException; public class PythonGlobalVarTest extends PythonParserTest { @Before public void setUp() { super.init(); } @Test public void should_detect_global_reference() throws IOException { String[] srcs = new String[] { "./src/test/resources/python-code-examples/global_test/file1.py", "./src/test/resources/python-code-examples/global_test/file2.py", }; for (String src:srcs) { PythonFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(true); Entity foo = entityRepo.getEntity(withPackageName(srcs[0],"foo")); this.assertContainsRelation(foo, DependencyType.USE, "global_var"); } }
935
25
75
java
depends
depends-master/src/test/java/depends/extractor/java/JavaCallExpressionTest.java
package depends.extractor.java; import static org.junit.Assert.assertEquals; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.entity.ContainerEntity; public class JavaCallExpressionTest extends JavaParserTest { @Before public void setUp() { super.init(); } @Test public void test() throws IOException { String src = "./src/test/resources/java-code-examples/SimpleExpressionCallTest.java"; JavaFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); } }
562
20.653846
93
java
depends
depends-master/src/test/java/depends/extractor/java/JavaAnnotationParserTest.java
package depends.extractor.java; import static org.junit.Assert.assertEquals; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.deptypes.DependencyType; public class JavaAnnotationParserTest extends JavaParserTest { @Before public void setUp() { super.init(); } @Test public void test_could_parse_annotationType() throws IOException { String src = "./src/test/resources/java-code-examples/AnnotationTest.java"; JavaFileParser parser =createParser(); parser.parse(src); resolveAllBindings(); assertEquals(1,entityRepo.getEntity("AnnotationTest.value").getRelations().size()); } @Test public void test_could_detect_annotation_in_class_level() throws IOException { String src = "./src/test/resources/java-code-examples/AnnotationTest.java"; JavaFileParser parser =createParser(); parser.parse(src); resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("TheClass"), DependencyType.ANNOTATION, "AnnotationTest"); } @Test public void test_could_detect_annotation_in_function_level() throws IOException { String src = "./src/test/resources/java-code-examples/AnnotationTest.java"; JavaFileParser parser =createParser(); parser.parse(src); resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("TheFunction.foo"), DependencyType.ANNOTATION, "AnnotationTest"); } @Test public void test_could_detect_no_annotation_in_function_level() throws IOException { String src = "./src/test/resources/java-code-examples/AnnotationTest.java"; JavaFileParser parser =createParser(); parser.parse(src); resolveAllBindings(); this.assertNotContainsRelation(entityRepo.getEntity("TheFunction.bar"), DependencyType.ANNOTATION, "AnnotationTest"); } @Test public void test_could_detect_annotation_in_miscs() throws IOException { String src = "./src/test/resources/java-code-examples/AnnotationTest.java"; JavaFileParser parser =createParser(); parser.parse(src); resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("TheClass.TheClass"), DependencyType.ANNOTATION, "AnnotationTest"); this.assertContainsRelation(entityRepo.getEntity("TheEnum"), DependencyType.ANNOTATION, "AnnotationTest"); this.assertContainsRelation(entityRepo.getEntity("TheInterface.foo"), DependencyType.ANNOTATION, "AnnotationTest"); this.assertContainsRelation(entityRepo.getEntity("TheInterface.theConst"), DependencyType.ANNOTATION, "AnnotationTest"); this.assertContainsRelation(entityRepo.getEntity("TheClass.theField"), DependencyType.ANNOTATION, "AnnotationTest"); } }
2,780
39.897059
128
java
depends
depends-master/src/test/java/depends/extractor/java/JavaCylicInheritTest.java
package depends.extractor.java; import org.junit.Before; import org.junit.Test; import java.io.IOException; public class JavaCylicInheritTest extends JavaParserTest{ @Before public void setUp() { super.init(); } @Test(timeout=3000L) public void test_cyclic_should_not_occur_inifinite_test() throws IOException { String src = "./src/test/resources/java-code-examples/CyclicInherit.java"; JavaFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); } }
517
22.545455
82
java
depends
depends-master/src/test/java/depends/extractor/java/JavaComplexExpressionTest.java
package depends.extractor.java; import static org.junit.Assert.assertEquals; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.entity.ContainerEntity; public class JavaComplexExpressionTest extends JavaParserTest { @Before public void setUp() { super.init(); } @Test public void test_complexExpression() throws IOException { String src = "./src/test/resources/java-code-examples/ComplexExpressionTest.java"; JavaFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); ContainerEntity entity = (ContainerEntity)(entityRepo.getEntity("ComplexExpressionTest.other")); assertEquals(3,entity.getRelations().size()); } }
740
25.464286
105
java
depends
depends-master/src/test/java/depends/extractor/java/JavaTypeInferUnderSamePackageTest.java
package depends.extractor.java; import static org.junit.Assert.assertEquals; import java.io.IOException; import org.junit.Before; import org.junit.Test; public class JavaTypeInferUnderSamePackageTest extends JavaParserTest{ @Before public void setUp() { super.init(); } @Test public void test_GenericTypeShouldBeIdentified() throws IOException { String src = "./src/test/resources/java-code-examples/TypeInferUnderSamePackageA.java"; JavaFileParser parser = createParser(); parser.parse(src); src = "./src/test/resources/java-code-examples/TypeInferUnderSamePackageB.java"; parser = createParser(); parser.parse(src); resolveAllBindings(); assertEquals(1,entityRepo.getEntity("x.TypeInferUnderSamePackageA").getRelations().size()); } }
814
28.107143
99
java
depends
depends-master/src/test/java/depends/extractor/java/JavaVarResolveTest.java
package depends.extractor.java; import depends.deptypes.DependencyType; import depends.entity.ContainerEntity; import depends.entity.Entity; import depends.entity.FunctionEntity; import depends.entity.TypeEntity; import org.junit.Before; import org.junit.Test; import java.io.IOException; import static org.junit.Assert.assertEquals; public class JavaVarResolveTest extends JavaParserTest{ @Before public void setUp() { super.init(); } @Test public void test_field_var_should_be_parsed() throws IOException { String src = "./src/test/resources/java-code-examples/FieldVar.java"; JavaFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); Entity classEntity = entityRepo.getEntity("FieldVar"); assertEquals(3,((TypeEntity)classEntity).getVars().size()); } @Test public void test_local_var_should_be_parsed() throws IOException { String src = "./src/test/resources/java-code-examples/LocalVar.java"; JavaFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); assertEquals(1,((TypeEntity)entityRepo.getEntity("LocalVar")).getVars().size()); assertEquals(1,((FunctionEntity)entityRepo.getEntity("LocalVar.foo")).getVars().size()); } @Test public void test_local_var_type_could_be_inferred() throws IOException { String src = "./src/test/resources/java-code-examples/LocalVarInferExample.java"; JavaFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); ContainerEntity e = (ContainerEntity) entityRepo.getEntity("LocalVarInferExample.setExample"); this.assertContainsRelation(e, DependencyType.CONTAIN, "MyInteger"); } @Test public void test_field_access_could_be_inferred() throws IOException { String src = "./src/test/resources/java-code-examples/ComplexExpressionExample.java"; JavaFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); Entity e = entityRepo.getEntity("test.ComplexExpressionExample.setExample"); this.assertContainsRelation(e, DependencyType.PARAMETER, "test.ClassA"); this.assertContainsRelation(e, DependencyType.CREATE, "test.ClassA"); this.assertContainsRelation(e, DependencyType.CALL, "test.ClassA"); this.assertContainsRelation(e, DependencyType.CAST, "test.ClassA"); this.assertContainsRelation(e, DependencyType.CALL, "test.ClassA.foo"); this.assertContainsRelation(e, DependencyType.CALL, "test.ClassA"); this.assertContainsRelation(e, DependencyType.USE, "test.ComplexExpressionExample.setExample.a3"); this.assertContainsRelation(e, DependencyType.USE, "test.ClassX.m"); this.assertContainsRelation(e, DependencyType.USE, "test.ComplexExpressionExample.setExample.a2"); this.assertContainsRelation(e, DependencyType.USE, "test.ClassA.x"); this.assertContainsRelation(e, DependencyType.USE, "test.ComplexExpressionExample.setExample.a"); } @Test public void test_long_static_function_should_be_inferred() throws IOException { String src = "./src/test/resources/java-code-examples/LongExpressionWithAbsolutePath.java"; JavaFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); assertEquals(5,entityRepo.getEntity("x.LongExpressionWithAbsolutePath.setExample").getRelations().size()); } @Test public void test_call_should_be_referred() throws IOException { String src = "./src/test/resources/java-code-examples/ExpressionCallTest.java"; JavaFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); assertEquals(10,entityRepo.getEntity("ValidateAll.validate").getRelations().size()); } @Test public void test_could_detect_type_argument_in_field() throws IOException { String src = "./src/test/resources/java-code-examples/TypeArgument.java"; JavaFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("JDepObject.cells"),DependencyType.PARAMETER, "JCellObject"); } }
4,238
40.970297
118
java
depends
depends-master/src/test/java/depends/extractor/java/JavaParameterParserTest.java
package depends.extractor.java; import static org.junit.Assert.assertEquals; import java.io.IOException; import org.junit.Before; import org.junit.Test; public class JavaParameterParserTest extends JavaParserTest { @Before public void setUp() { super.init(); } @Test public void test_parameter() throws IOException { String src = "./src/test/resources/java-code-examples/FunctionParameters.java"; JavaFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); assertEquals(4,entityRepo.getEntity("FunctionParameters.function_with_parameters_same_type").getRelations().size()); } }
654
24.192308
124
java
depends
depends-master/src/test/java/depends/extractor/java/UnsolvedSymbolsTest.java
package depends.extractor.java; import depends.extractor.UnsolvedBindings; import org.junit.Before; import org.junit.Test; import java.io.IOException; import java.util.Set; import static org.junit.Assert.assertEquals; public class UnsolvedSymbolsTest extends JavaParserTest { @Before public void setUp() { super.init(); } @Test public void test_missing_import() throws IOException { String src = "./src/test/resources/java-code-examples/UnsolvedSymbols/MissingImport.java"; JavaFileParser parser = createParser(); parser.parse(src); Set<UnsolvedBindings> missing = resolveAllBindings(); assertEquals(1,missing.size()); assertEquals("a.b",missing.iterator().next().getRawName()); } }
744
25.607143
98
java
depends
depends-master/src/test/java/depends/extractor/java/JavaParserTest.java
package depends.extractor.java; import depends.extractor.ParserTest; public abstract class JavaParserTest extends ParserTest{ public void init() { langProcessor = new JavaProcessor(); super.init(); } public JavaFileParser createParser() { return new JavaFileParser(entityRepo, bindingResolver); } }
314
20
57
java
depends
depends-master/src/test/java/depends/extractor/java/JavaParseErrorFileTest.java
package depends.extractor.java; import java.io.IOException; import org.junit.Before; import org.junit.Test; public class JavaParseErrorFileTest extends JavaParserTest{ @Before public void setUp() { super.init(); } @Test public void test_incomplete_file_should_not_stop_process() throws IOException { String src = "./src/test/resources/java-code-examples/IncompleteFile.java"; JavaFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); } @Test public void test_should_resolve_types() throws IOException { String src = "./src/test/resources/java-code-examples/EclipseTestBase_No_ResponseDuirngTypeResolve.java"; JavaFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); } }
803
24.125
113
java
depends
depends-master/src/test/java/depends/extractor/java/JavaExpressionCreatorTest.java
package depends.extractor.java; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.deptypes.DependencyType; import depends.entity.Entity; import depends.extractor.FileParser; public class JavaExpressionCreatorTest extends JavaParserTest{ @Before public void setUp() { super.init(); } @Test public void test_should_found_creator_with_full_path() throws IOException { String[] srcs = new String[] { "./src/test/resources/java-code-examples/JavaExpressionCreator/A.java", "./src/test/resources/java-code-examples/JavaExpressionCreator/b/B.java", }; for (String src:srcs) { FileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); Entity entity = (entityRepo.getEntity("A.foo")); this.assertContainsRelation(entity, DependencyType.CREATE, "b.B"); } @Test public void test_should_found_creator_with_imported_class() throws IOException { String[] srcs = new String[] { "./src/test/resources/java-code-examples/JavaExpressionCreator/X.java", "./src/test/resources/java-code-examples/JavaExpressionCreator/b/B.java", }; for (String src:srcs) { FileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); Entity entity = (entityRepo.getEntity("X.foo")); this.assertContainsRelation(entity, DependencyType.CREATE, "b.B"); } }
1,462
26.092593
81
java
depends
depends-master/src/test/java/depends/extractor/java/JavaInternalClassTest.java
package depends.extractor.java; import static org.junit.Assert.assertNotNull; import java.io.IOException; import org.junit.Before; import org.junit.Test; public class JavaInternalClassTest extends JavaParserTest{ @Before public void setUp() { super.init(); } @Test public void test_parameter() throws IOException { String src = "./src/test/resources/java-code-examples/InternalClass.java"; JavaFileParser parser = createParser(); parser.parse(src); assertNotNull(entityRepo.getEntity("a.InternalClass.Internal")); } }
565
21.64
82
java
depends
depends-master/src/test/java/depends/extractor/java/JavaEmbededClassTest.java
package depends.extractor.java; import static org.junit.Assert.assertEquals; import java.io.IOException; import org.junit.Before; import org.junit.Test; public class JavaEmbededClassTest extends JavaParserTest{ @Before public void setUp() { super.init(); } @Test public void test_EmbededTypeWithImport() throws IOException { String src = "./src/test/resources/java-code-examples/EmbededTest.java"; JavaFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); assertEquals(1,entityRepo.getEntity("x.EmbededTest").getRelations().size()); } @Test public void test_EmbededTypeWithoutImport() throws IOException { String src = "./src/test/resources/java-code-examples/EmbededTest.java"; JavaFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); assertEquals(1,entityRepo.getEntity("x.EmbededTest2").getRelations().size()); } }
962
28.181818
85
java
depends
depends-master/src/test/java/depends/extractor/java/JavaFileImportTest.java
package depends.extractor.java; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.deptypes.DependencyType; import depends.entity.TypeEntity; import depends.extractor.FileParser; public class JavaFileImportTest extends JavaParserTest{ @Before public void setUp() { super.init(); } @Test public void test_wildcard_import_should_be_lookedup() throws IOException { String[] srcs = new String[] { "./src/test/resources/java-code-examples/JavaFileImportExample/a/Importing.java", "./src/test/resources/java-code-examples/JavaFileImportExample/b/B.java", }; for (String src:srcs) { FileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); TypeEntity type = (TypeEntity)(entityRepo.getEntity("a.Importing")); this.assertContainsRelation(type, DependencyType.INHERIT, "b.B"); } }
921
24.611111
88
java
depends
depends-master/src/test/java/depends/extractor/java/JavaGenericTypeTest.java
package depends.extractor.java; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.deptypes.DependencyType; public class JavaGenericTypeTest extends JavaParserTest{ @Before public void setUp() { super.init(); } @Test public void test_GenericTypeShouldBeIdentified() throws IOException { String src = "./src/test/resources/java-code-examples/GenericTypeTest.java"; JavaFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("x.GenericTypeTest.v"), DependencyType.PARAMETER, "x.Parent2.Enum"); } @Test public void test_GenericTypeEmbededShouldBeIdentified() throws IOException { String src = "./src/test/resources/java-code-examples/GenericTypeEmbededTest.java"; JavaFileParser parser = createParser(); parser.parse(src); resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("GenericTypeEmbededTest"), DependencyType.CONTAIN, "MyHashMap"); this.assertContainsRelation(entityRepo.getEntity("GenericTypeEmbededTest.data"), DependencyType.PARAMETER, "MyList"); this.assertContainsRelation(entityRepo.getEntity("GenericTypeEmbededTest.data"), DependencyType.PARAMETER, "MyArray"); } }
1,363
33.1
91
java
depends
depends-master/src/test/java/depends/extractor/java/InheritTypeTest.java
package depends.extractor.java; import static org.junit.Assert.assertEquals; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.deptypes.DependencyType; public class InheritTypeTest extends JavaParserTest { @Before public void setUp() { super.init(); } @Test public void should_handle_inherited_type_correctly() throws IOException { String src = "./src/test/resources/java-code-examples/InheritTest.java"; JavaFileParser parser =createParser(); parser.parse(src); resolveAllBindings(); assertEquals(1,entityRepo.getEntity("InheritTest").getRelations().size()); } }
658
24.346154
82
java
depends
depends-master/src/test/java/depends/extractor/golang/GoFunctionsTest.java
package depends.extractor.golang; import depends.entity.TypeEntity; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import java.io.IOException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; public class GoFunctionsTest extends GolangParserTest { @Before public void setUp() { super.init(); } @Test public void test_could_parse_function() throws IOException { String src = "./src/test/resources/go-code-examples/func.go"; GoFileParser parser =createParser(); parser.parse(src); resolveAllBindings(); assertNotNull(entityRepo.getEntity("main")); } @Ignore public void test_could_parse_struct_type() throws IOException { String src = "./src/test/resources/go-code-examples/struct.go"; GoFileParser parser =createParser(); parser.parse(src); resolveAllBindings(); assertNotNull(entityRepo.getEntity("Books")); } @Ignore public void test_could_parse_struct_members() throws IOException { String src = "./src/test/resources/go-code-examples/struct.go"; GoFileParser parser =createParser(); parser.parse(src); resolveAllBindings(); assertNotNull(entityRepo.getEntity("Books")); TypeEntity book = (TypeEntity)entityRepo.getEntity("Books"); assertEquals(4,book.getChildren().size()); } }
1,334
26.8125
69
java
depends
depends-master/src/test/java/depends/extractor/golang/GolangParserTest.java
package depends.extractor.golang; import depends.extractor.ParserTest; public abstract class GolangParserTest extends ParserTest{ public void init() { langProcessor = new GoProcessor(); super.init(); } public GoFileParser createParser() { return new GoFileParser(entityRepo, bindingResolver); } }
313
17.470588
58
java
depends
depends-master/src/test/java/depends/format/json/JsonFormatDependencyDumperTest.java
package depends.format.json; import depends.format.excel.ExcelXlsxFormatDependencyDumper; import depends.matrix.core.DependencyMatrix; import org.junit.Before; import org.junit.Ignore; import org.junit.Rule; import org.junit.rules.TemporaryFolder; import java.io.File; import java.io.IOException; import java.util.ArrayList; public class JsonFormatDependencyDumperTest { DependencyMatrix dependencyMatrix; @Rule public TemporaryFolder folder= new TemporaryFolder(); @Before public void init() { int SIZE = 4000; dependencyMatrix = new DependencyMatrix(SIZE*100,null,false); for (int i=0;i<SIZE;i++) dependencyMatrix.addNode(""+i,i); System.out.print("here1"); for (int i=0;i<SIZE;i++) { System.out.println("in "+i); for (int j=0;j<1500;j++) { dependencyMatrix.addDependency("t", i, j, 0, new ArrayList<>()); } } System.out.print("here2"); } @Ignore public void testJson() throws IOException { String projectName = "test"; String outputDir = folder.getRoot().getAbsolutePath(); JsonFormatDependencyDumper dumper = new JsonFormatDependencyDumper(dependencyMatrix, projectName, outputDir); dumper.output(); System.out.println(outputDir+File.separator+"test.json"); } @Ignore public void testExcel() throws IOException { String projectName = "test"; String outputDir = folder.getRoot().getAbsolutePath(); ExcelXlsxFormatDependencyDumper dumper = new ExcelXlsxFormatDependencyDumper(dependencyMatrix, projectName, outputDir); dumper.output(); System.out.println(outputDir+File.separator+"test.xlsx"); } }
1,606
27.192982
121
java
depends
depends-master/src/test/resources/java-code-examples/ExpressionCallTest.java
import java.io.IOException; import java.net.InetSocketAddress; import java.util.Iterator; import org.apache.avro.Protocol; import org.apache.avro.Schema; import org.apache.avro.SchemaValidationException; import org.apache.avro.SchemaValidationStrategy; import org.apache.avro.SchemaValidator; import org.apache.avro.TestProtocolGeneric.TestResponder; import org.apache.avro.generic.GenericData; import org.apache.avro.ipc.Requestor; import org.apache.avro.ipc.SaslSocketServer; import org.apache.avro.ipc.SaslSocketTransceiver; import org.apache.avro.ipc.Transceiver; import org.apache.avro.ipc.generic.GenericRequestor; public interface SchemaValidationStrategy { /** * Validates that one schema is compatible with another. * * @throws SchemaValidationException if the schemas are not compatible. */ void validate(Schema toValidate, Schema existing) throws SchemaValidationException; } public class GenericRequestor extends Requestor { public GenericRequestor(Protocol protocol, Transceiver transceiver) throws IOException { this(protocol, transceiver, GenericData.get()); } } public final class ValidateAll implements SchemaValidator { private final SchemaValidationStrategy strategy; public void validate(Schema toValidate, Iterable<Schema> schemasInOrder) throws SchemaValidationException { Iterator<Schema> schemas = schemasInOrder.iterator(); while (schemas.hasNext()) { Schema existing = schemas.next(); strategy.validate(toValidate, existing); } } public void testStartServer() throws Exception { requestor = new GenericRequestor(PROTOCOL, client); } }
1,657
32.16
74
java
depends
depends-master/src/test/resources/java-code-examples/GenericTypeTest.java
package x; import x.Parent.Enum; import java.io; import java.util.List; class Parent2 { enum Enum{ a,b } } public class GenericTypeTest{ List<Parent2.Enum> v; public <D> File write(D... data) throws IOException { } }
231
11.888889
55
java
depends
depends-master/src/test/resources/java-code-examples/InternalClass.java
package a; public class InternalClass { class Internal{ } }
64
9.833333
28
java
depends
depends-master/src/test/resources/java-code-examples/TypeInferUnderSamePackageB.java
package x; class TypeInferUnderSamePackageB{ class SubType { } }
69
10.666667
33
java
depends
depends-master/src/test/resources/java-code-examples/TypeArgument.java
import java.util.ArrayList; import javax.xml.bind.annotation.XmlRootElement; import depends.format.json.JCellObject; class JCellObject{ } public class JDepObject { private ArrayList<JCellObject> cells; }
212
16.75
48
java
depends
depends-master/src/test/resources/java-code-examples/InheritTest.java
class A{ A(){} } public class InheritTest extends A{ }
58
7.428571
35
java
depends
depends-master/src/test/resources/java-code-examples/SimpleExpressionCallTest.java
public class SimpleExpressionCallTest { public SimpleExpressionCallTest foo(){ return this; } public SimpleExpressionCallTest bar(){ _this = this; _this[0].foo().bar().foo(); return this; } }
245
19.5
42
java
depends
depends-master/src/test/resources/java-code-examples/CyclicInherit.java
class A extends C{ A(){ this.a = 1; this.foo(); foo(); } } class B extends A{ } class C extends B{ }
122
5.15
18
java
depends
depends-master/src/test/resources/java-code-examples/ComplexExpressionTest.java
class B{ static String c; } class ComplexExpressionTest{ String foo() { return B.class.getName(); } String bar() { B b; return b.getClass().getName(); } String other() { return B.c; } }
203
11
32
java
depends
depends-master/src/test/resources/java-code-examples/EclipseTestBase_No_ResponseDuirngTypeResolve.java
/******************************************************************************* * Copyright (c) 2007, 2014 BEA Systems, Inc. and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * * Contributors: * BEA Systems, Inc. - initial API and implementation * Jesper Steen Moller - Bug 412150 [1.8] [compiler] Enable reflected parameter names during annotation processing *******************************************************************************/ package org.eclipse.jdt.apt.pluggable.tests; import java.io.File; import java.io.InputStream; import java.net.URL; import java.util.Map; import javax.lang.model.SourceVersion; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.jdt.apt.core.internal.util.FactoryContainer; import org.eclipse.jdt.apt.core.internal.util.FactoryContainer.FactoryType; import org.eclipse.jdt.apt.core.internal.util.FactoryPath; import org.eclipse.jdt.apt.core.util.AptConfig; import org.eclipse.jdt.core.IClasspathAttribute; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.tests.builder.BuilderTests; import org.eclipse.jdt.core.tests.util.Util; import org.eclipse.jdt.internal.core.ClasspathEntry; import junit.framework.Test; public class TestBase extends BuilderTests { protected static final String JAVA_16_COMPLIANCE = "1.6"; protected static final String JAVA_18_COMPLIANCE = "1.8"; protected static final String JAVA_9_COMPLIANCE = "9"; protected String _projectName; protected static int _projectSerial = 0; // used to create unique project names, to avoid resource deletion problems public TestBase(String name) { super(name); } public static Test suite() { throw new IllegalStateException("This is a base test class whose suite() method must not be called.\n" + "This exception is thrown to avoid running org.eclipse.jdt.core.tests.builder.BuilderTests#suite() twice."); } /** * Extract lib/annotations.jar from the test bundle and add it to the specified project */ private static void addAnnotationJar(IJavaProject jproj, boolean addToModulePath) throws Exception { final String resName = "lib/annotations.jar"; // name in bundle final String libName = resName; // name in destination project InputStream is = null; URL resURL = Apt6TestsPlugin.thePlugin().getBundle().getEntry(resName); is = resURL.openStream(); IPath projPath = jproj.getPath(); IProject proj = jproj.getProject(); IFile libFile = proj.getFile(libName); env.addFolder(projPath, "lib"); if (libFile.exists()) { libFile.setContents(is, true, false, null); } else { libFile.create(is, true, null); } if (addToModulePath) { IClasspathAttribute[] attributes = { JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") }; env.addEntry(projPath, JavaCore.newLibraryEntry(libFile.getFullPath(), null, null, ClasspathEntry.NO_ACCESS_RULES, attributes, false)); } else { env.addLibrary(projPath, libFile.getFullPath(), null, null); } } /** * Create a java project with java libraries and test annotations on classpath * (compiler level is 1.6). Use "src" as source folder and "bin" as output folder. APT * is not enabled. * * @param projectName * @return a java project that has been added to the current workspace. * @throws Exception */ protected static IJavaProject createJavaProject(final String projectName) throws Exception { IPath projectPath = env.addProject(projectName, JAVA_16_COMPLIANCE); env.addExternalJars(projectPath, Util.getJavaClassLibs()); // remove old package fragment root so that names don't collide env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ final IJavaProject javaProj = env.getJavaProject(projectPath); addAnnotationJar(javaProj, false); return javaProj; } /** * Create a java project with java libraries and test annotations on classpath * (compiler level is 1.8). Use "src" as source folder and "bin" as output folder. APT * is not enabled. * * @param projectName * @return a java project that has been added to the current workspace. * @throws Exception */ protected static IJavaProject createJava8Project(final String projectName) throws Exception { // Note, make sure this is run only with a JRE 8 and above. IPath projectPath = env.addProject(projectName, JAVA_18_COMPLIANCE); env.addExternalJars(projectPath, Util.getJavaClassLibs()); // remove old package fragment root so that names don't collide env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ final IJavaProject javaProj = env.getJavaProject(projectPath); javaProj.getProject().getFolder("prebuilt").create(true, true, null); javaProj.getProject().getFolder("prebuilt").getFolder("p").create(true, true, null); env.addClassFolder(projectPath, projectPath.append("prebuilt"), true); addAnnotationJar(javaProj, false); return javaProj; } /** * Create a java project with java libraries and test annotations on modulepath * (compiler level is 1.9). Use "src" as source folder and "bin" as output folder. APT * is not enabled. * * @param projectName * @return a java project that has been added to the current workspace. * @throws Exception */ protected static IJavaProject createJava9Project(final String projectName) throws Exception { // Note, make sure this is run only with a JRE 9 and above. IPath projectPath = env.addProject(projectName, JAVA_9_COMPLIANCE); env.addExternalJars(projectPath, Util.getJavaClassLibs()); // remove old package fragment root so that names don't collide env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ final IJavaProject javaProj = env.getJavaProject(projectPath); addAnnotationJar(javaProj, true); return javaProj; } /** * Ensure that there are no Java 5 processors on the factory path, as they can cause * units to be multiply compiled, which can mess up tests that expect a certain number * of compilations to occur. * @param jproj the project whose factory path will be edited * @throws CoreException */ protected void disableJava5Factories(IJavaProject jproj) throws CoreException { FactoryPath fp = (FactoryPath) AptConfig.getFactoryPath(jproj); for (Map.Entry<FactoryContainer, FactoryPath.Attributes> entry : fp.getAllContainers().entrySet()) { if (entry.getKey().getType() == FactoryType.PLUGIN) { String id = entry.getKey().getId(); if (!Apt6TestsPlugin.PLUGIN_ID.equals(id)) { fp.disablePlugin(id); } } } AptConfig.setFactoryPath(jproj, fp); } /** * Verify that an expected file exists within a project. * @param fileName the filename relative to the project root. */ protected void expectingFile(IProject proj, String fileName) throws Exception { IPath path = proj.getLocation().append(fileName); File file = new File(path.toOSString()); assertTrue("Expected file " + fileName + " was missing from project", file != null && file.exists()); } /** * Verify that an expected file exists within a project. * @param fileName the filename relative to the project root. */ protected void expectingNoFile(IProject proj, String fileName) throws Exception { IPath path = proj.getLocation().append(fileName); File file = new File(path.toOSString()); boolean exists = file.exists(); // work around a timing bug in some versions of JRE 1.6 on Linux: // Before assuming the test has failed, wait half a second and try again. // This delay is not encountered when the test is passing normally. if (exists) { Thread.sleep(500); exists = file.exists(); } assertTrue("File " + fileName + " was expected to not exist", file == null || !exists); } @Override protected void setUp() throws Exception { super.setUp(); env.setAutoBuilding(false); _projectName = String.format("testproj%04d", ++_projectSerial); } public boolean canRunJava9() { try { SourceVersion.valueOf("RELEASE_9"); } catch(IllegalArgumentException iae) { return false; } return true; } }
8,747
38.405405
117
java
depends
depends-master/src/test/resources/java-code-examples/LocalVarInferExample.java
class MyString{ } class MyInteger{ } @interface MyAnnotation{ } @MyAnnotation public class LocalVarInferExample { MyString a; void setExample(MyString b) { //param MyInteger x; //define x=1; //Set x b="2"; //Set b x=b.length(); //Set x (x=b)+=1; //Set x ++x; //Set x x--; //Set x --x; //Set x } }
324
12
49
java
depends
depends-master/src/test/resources/java-code-examples/IncompleteFile.java
protected static Logger log = Logger.getLogger(InsightManagerInitializer222.class);
84
41.5
83
java
depends
depends-master/src/test/resources/java-code-examples/FieldVar.java
public class FieldVar { String a; public String b,c; }
57
10.6
23
java
depends
depends-master/src/test/resources/java-code-examples/TypeInferUnderSamePackageA.java
package x; class TypeInferUnderSamePackageA{ TypeInferUnderSamePackageB.SubType v; }
85
20.5
38
java
depends
depends-master/src/test/resources/java-code-examples/GenericTypeEmbededTest.java
class MyHashMap<T1, T2>{ } class MyList<T> { } class MyArray<T>{ } class GenericTypeEmbededTest{ MyHashMap<String, MyList<MyArray<Integer>> > data; }
160
9.733333
52
java
depends
depends-master/src/test/resources/java-code-examples/LongExpressionWithAbsolutePath.java
package x; class MyString{ static void foo() {} } public class LongExpressionWithAbsolutePath { public void setExample(Object m) { x.MyString.foo(); } }
158
14.9
45
java
depends
depends-master/src/test/resources/java-code-examples/FunctionParameters.java
public class FunctionParameters { public void func_without_parameter() { } public void function_with_one_parameter(Integer a) { } public void function_with_two_parameter(Integer a, String b) { } public void function_with_parameters_same_type(Integer a, String b, Integer c) { } }
296
21.846154
81
java
depends
depends-master/src/test/resources/java-code-examples/EmbededTest.java
package x; import x.Parent.Enum; class Parent { enum Enum{ a,b } } class Parent2 { enum Enum{ a,b } } public class EmbededTest{ Parent.Enum v; } class EmbededTest2{ Parent2.Enum v; }
198
8.045455
25
java
depends
depends-master/src/test/resources/java-code-examples/LocalVar.java
public class LocalVar { String a; void foo(String b) { String a; } }
74
9.714286
23
java
depends
depends-master/src/test/resources/java-code-examples/ComplexExpressionExample.java
package test; class ClassX{ Integer m; } class ClassA{ Integer t; ClassX x; int foo(); } public class ComplexExpressionExample { void setExample(ClassA a) { //parameter a(1) (new ClassA()).x.m = 3; //set (newA) x, m (2) a.x.m = 1; //set m (1), use a, x? or set a,x? ClassA a2 = new ClassA(); //def a2 (1), set a2 (ClassA)a.foo(); a2.x.m = 1; //set a2, set x, set m (3) ClassA a3[] = new ClassA[10]; //def a3(1) a3[1].x.m = 3; //still lack 1 //set a3,t(2) } }
558
23.304348
70
java
depends
depends-master/src/test/resources/java-code-examples/AnnotationTest.java
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) public @interface AnnotationTest { String value(); } @AnnotationTest class TheClass{ @AnnotationTest TheClass(){} @AnnotationTest int theField; } class TheFunction{ @AnnotationTest void foo() {} void bar() {} } @AnnotationTest enum TheEnum{ } @AnnotationTest interface TheInterface{ @AnnotationTest void foo() {} @AnnotationTest int theConst = 5; }
524
10.931818
44
java
depends
depends-master/src/test/resources/java-code-examples/JavaFileImportExample/a/Importing.java
package a; import b.*; class Importing extends B{ }
53
8
26
java
depends
depends-master/src/test/resources/java-code-examples/JavaFileImportExample/b/B.java
package b; class B{ }
23
3.8
10
java
depends
depends-master/src/test/resources/java-code-examples/UnsolvedSymbols/MissingImport.java
import a.b; public class MissingImport{ }
43
10
27
java
depends
depends-master/src/test/resources/java-code-examples/JavaExpressionCreator/X.java
import b.*; public class X{ void foo() { Object x = new B(); } }
68
10.5
21
java
depends
depends-master/src/test/resources/java-code-examples/JavaExpressionCreator/A.java
public class A{ void foo() { Object x = new b.B(); } }
58
10.8
23
java
depends
depends-master/src/test/resources/java-code-examples/JavaExpressionCreator/b/B.java
package b; public class B{ }
30
6.75
15
java
depends
depends-master/src/main/java/depends/Main.java
/* MIT License Copyright (c) 2018-2019 Gang ZHANG Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package depends; import depends.addons.DV8MappingFileBuilder; import depends.entity.repo.EntityRepo; import depends.extractor.AbstractLangProcessor; import depends.extractor.LangProcessorRegistration; import depends.extractor.UnsolvedBindings; import depends.format.DependencyDumper; import depends.format.detail.UnsolvedSymbolDumper; import depends.generator.DependencyGenerator; import depends.generator.FileDependencyGenerator; import depends.generator.FunctionDependencyGenerator; import depends.generator.StructureDependencyGenerator; import depends.matrix.core.DependencyMatrix; import depends.relations.BindingResolver; import depends.relations.IBindingResolver; import depends.relations.RelationCounter; import edu.emory.mathcs.backport.java.util.Arrays; import multilang.depends.util.file.FileUtil; import multilang.depends.util.file.FolderCollector; import multilang.depends.util.file.TemporaryFile; import multilang.depends.util.file.path.*; import multilang.depends.util.file.strip.LeadingNameStripper; import net.sf.ehcache.CacheManager; import org.codehaus.plexus.util.StringUtils; import picocli.CommandLine; import picocli.CommandLine.PicocliException; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Set; /** * The entry pooint of depends */ public class Main { public static void main(String[] args) { try { LangRegister langRegister = new LangRegister(); langRegister.register(); DependsCommand appArgs = CommandLine.populateCommand(new DependsCommand(), args); if (appArgs.help) { CommandLine.usage(new DependsCommand(), System.out); System.exit(0); } verifyParameters(appArgs); executeCommand(appArgs); } catch (Exception e) { if (e instanceof PicocliException) { CommandLine.usage(new DependsCommand(), System.out); } else if (e instanceof ParameterException){ System.err.println(e.getMessage()); }else { System.err.println("Exception encountered. If it is a design error, please report issue to us." ); e.printStackTrace(); } System.exit(0); } } private static void verifyParameters(DependsCommand args) throws ParameterException { String[] granularities = args.getGranularity(); List<String> validGranularities = Arrays.asList(new String[]{"file", "method", "structure"}); for (String g:granularities){ if (!validGranularities.contains(g)){ throw new ParameterException("granularity is invalid:"+g); } } } @SuppressWarnings("unchecked") private static void executeCommand(DependsCommand args) throws ParameterException { String lang = args.getLang(); String inputDir = args.getSrc(); String[] includeDir = args.getIncludes(); String outputName = args.getOutputName(); String outputDir = args.getOutputDir(); String[] outputFormat = args.getFormat(); inputDir = FileUtil.uniqFilePath(inputDir); if (args.isAutoInclude()) { includeDir = appendAllFoldersToIncludePath(inputDir, includeDir); } AbstractLangProcessor langProcessor = LangProcessorRegistration.getRegistry().getProcessorOf(lang); if (langProcessor == null) { System.err.println("Not support this language: " + lang); return; } IBindingResolver bindingResolver = new BindingResolver(langProcessor, args.isOutputExternalDependencies(), args.isDuckTypingDeduce()); long startTime = System.currentTimeMillis(); //step1: build data EntityRepo entityRepo = langProcessor.buildDependencies(inputDir, includeDir, bindingResolver); new RelationCounter(entityRepo,langProcessor, bindingResolver).computeRelations(); System.out.println("Dependency done...."); //step2: generate dependencies matrix List<DependencyGenerator> dependencyGenerators = getDependencyGenerators(args, inputDir); for (DependencyGenerator dependencyGenerator:dependencyGenerators) { DependencyMatrix matrix = dependencyGenerator.identifyDependencies(entityRepo, args.getTypeFilter()); DependencyDumper output = new DependencyDumper(matrix); output.outputResult(outputName+"-"+dependencyGenerator.getType(), outputDir, outputFormat); } if (args.isOutputExternalDependencies()) { Set<UnsolvedBindings> unsolved = langProcessor.getExternalDependencies(); UnsolvedSymbolDumper unsolvedSymbolDumper = new UnsolvedSymbolDumper(unsolved,args.getOutputName(),args.getOutputDir(), new LeadingNameStripper(args.isStripLeadingPath(),inputDir,args.getStrippedPaths())); unsolvedSymbolDumper.output(); } long endTime = System.currentTimeMillis(); TemporaryFile.getInstance().delete(); CacheManager.create().shutdown(); System.out.println("Consumed time: " + (float) ((endTime - startTime) / 1000.00) + " s, or " + (float) ((endTime - startTime) / 60000.00) + " min."); if ( args.isDv8map()) { DV8MappingFileBuilder dv8MapfileBuilder = new DV8MappingFileBuilder(langProcessor.supportedRelations()); dv8MapfileBuilder.create(outputDir+ File.separator+"depends-dv8map.mapping"); } } private static String[] appendAllFoldersToIncludePath(String inputDir, String[] includeDir) { FolderCollector includePathCollector = new FolderCollector(); List<String> additionalIncludePaths = includePathCollector.getFolders(inputDir); additionalIncludePaths.addAll(Arrays.asList(includeDir)); includeDir = additionalIncludePaths.toArray(new String[] {}); return includeDir; } private static List<DependencyGenerator> getDependencyGenerators(DependsCommand app, String inputDir) throws ParameterException { FilenameWritter filenameWritter = new EmptyFilenameWritter(); if (!StringUtils.isEmpty(app.getNamePathPattern())) { if (app.getNamePathPattern().equals("dot")|| app.getNamePathPattern().equals(".")) { filenameWritter = new DotPathFilenameWritter(); }else if (app.getNamePathPattern().equals("unix")|| app.getNamePathPattern().equals("/")) { filenameWritter = new UnixPathFilenameWritter(); }else if (app.getNamePathPattern().equals("windows")|| app.getNamePathPattern().equals("\\")) { filenameWritter = new WindowsPathFilenameWritter(); }else{ throw new ParameterException("Unknown name pattern paremater:" + app.getNamePathPattern()); } } List<DependencyGenerator> dependencyGenerators = new ArrayList<>(); for (int i=0;i<app.getGranularity().length;i++) { /* by default use file dependency generator */ DependencyGenerator dependencyGenerator = null; /* method parameter means use method generator */ if (app.getGranularity()[i].equals("method")) dependencyGenerator = new FunctionDependencyGenerator(); else if (app.getGranularity()[i].equals("file")) dependencyGenerator = new FileDependencyGenerator(); else if (app.getGranularity()[i].equals("structure")) dependencyGenerator = new StructureDependencyGenerator(); dependencyGenerators.add(dependencyGenerator); if (app.isStripLeadingPath() || app.getStrippedPaths().length > 0) { dependencyGenerator.setLeadingStripper(new LeadingNameStripper(app.isStripLeadingPath(), inputDir, app.getStrippedPaths())); } if (app.isDetail()) { dependencyGenerator.setGenerateDetail(true); } dependencyGenerator.setOutputSelfDependencies(app.isOutputSelfDependencies()); dependencyGenerator.setFilenameRewritter(filenameWritter); } return dependencyGenerators; } }
8,414
40.25
136
java
depends
depends-master/src/main/java/depends/LangRegister.java
/* MIT License Copyright (c) 2018-2019 Gang ZHANG Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package depends; import depends.extractor.AbstractLangProcessor; import depends.extractor.LangProcessorRegistration; public class LangRegister { public LangRegister() { add (new depends.extractor.java.JavaProcessor()); add (new depends.extractor.cpp.CppProcessor()); add (new depends.extractor.ruby.RubyProcessor()); add (new depends.extractor.pom.PomProcessor()); add (new depends.extractor.kotlin.KotlinProcessor()); add (new depends.extractor.python.union.PythonProcessor()); add (new depends.extractor.golang.GoProcessor()); } public void register() { } private void add(AbstractLangProcessor langProcessor) { LangProcessorRegistration.getRegistry().register(langProcessor); } }
1,793
34.176471
78
java
depends
depends-master/src/main/java/depends/DependsCommand.java
/* MIT License Copyright (c) 2018-2019 Gang ZHANG Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package depends; import depends.deptypes.DependencyType; import depends.extractor.LangProcessorRegistration; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; import java.util.ArrayList; import java.util.List; @Command(name = "depends") public class DependsCommand { public static class SupportedLangs extends ArrayList<String> { private static final long serialVersionUID = 1L; public SupportedLangs() { super( LangProcessorRegistration.getRegistry().getLangs()); } } public static class SupportedTypes extends ArrayList<String> { private static final long serialVersionUID = 1L; public SupportedTypes() { super( DependencyType.allDependencies()); } } @Parameters(index = "0", completionCandidates = DependsCommand.SupportedLangs.class, description = "The lanauge of project files: [${COMPLETION-CANDIDATES}]") private String lang; @Parameters(index = "1", description = "The directory to be analyzed") private String src; @Parameters(index = "2", description = "The output file name") private String output; @Option(names = {"-f", "--format"},split=",", description = "the output format: [json(default),xml,excel,detail,dot,plantuml]") private String[] format=new String[]{"json"}; @Option(names = {"-d", "--dir"}, description = "The output directory") private String dir; @Option(names = {"-m", "--map"}, description = "Output DV8 dependency map file.") private boolean dv8map = true; @Option(names = {"-s", "--strip-leading-path"}, description = "Strip the leading path.") private boolean stripLeadingPath = false; @Option(names = {"--strip-paths"}, split=",", description = "The path(s) to be stripped. if -s enabled, the path(s) start after <src>. " + "Otherwise, the path(s) should be valid.") private String[] strippedPaths = new String[]{}; @Option(names = {"-g", "--granularity"}, split=",", description = "Granularity of dependency.[file(default),method,structure]") private String[] granularity=new String[]{"file"}; @Option(names = {"-p", "--namepattern"}, description = "The name path pattern.[dot(.), unix(/) or windows(\\)") private String namePathPattern=""; @Option(names = {"-i","--includes"},split=",", description = "The files of searching path") private String[] includes = new String[] {}; @Option(names = {"--auto-include"},split=",", description = "auto include all paths under the source path (please notice the potential side effect)") private boolean autoInclude = false; @Option(names = {"--detail"},split=",", description = "add detail dependency information to output (only applicable for JSON output format)") private boolean detail = false; @Option(names = {"--auto-stub"},split=",", description = "create stub files for unsolved symbols (exprimental feature, only for java)") private boolean autoStub = false; @Option(names = {"--type-filter"},split=",", completionCandidates = DependsCommand.SupportedTypes.class, description = "only filter the listed dependency types[${COMPLETION-CANDIDATES}]") private String[] typeFilter=new String[]{}; @Option(names = {"--external-deps"}, description = "Output external dependencies") private boolean outputExternalDependencies = false; @Option(names = {"--duck-typing-deduce"}, description = "Deduce implicit variable types") private boolean duckTypingDeduce = true; @Option(names = {"--output-self-deps"}, description = "Output self dependencies") private boolean outputSelfDependencies = false; @Option(names = {"-h","--help"}, usageHelp = true, description = "display this help and exit") boolean help; public DependsCommand() { } public String getLang() { return lang; } public void setLang(String lang) { this.lang = lang; } public String getSrc() { return src; } public void setSrc(String src) { this.src = src; } public String getOutputName() { return output; } public void setOutput(String output) { this.output = output; } public String[] getFormat() { return format; } public String getOutputDir() { if (dir==null) { dir = System.getProperty("user.dir"); } return dir; } public boolean isDv8map() { return dv8map; } public String[] getIncludes() { return includes; } public boolean isHelp() { return help; } public String[] getGranularity() { return granularity; } public String getNamePathPattern() { return namePathPattern; } public boolean isStripLeadingPath() { return stripLeadingPath; } public boolean isAutoInclude () { return autoInclude; } public boolean isDetail () { return detail; } public String[] getStrippedPaths() { return strippedPaths; } public void setStrippedPaths(String[] strippedPaths) { this.strippedPaths = strippedPaths; } public boolean isAutoStub() { return autoStub; } public List<String> getTypeFilter() { if (typeFilter.length==0) { return DependencyType.allDependencies(); } return java.util.Arrays.asList(typeFilter); } public boolean isOutputExternalDependencies() { return outputExternalDependencies; } public boolean isOutputSelfDependencies() { return outputSelfDependencies; } public boolean isDuckTypingDeduce() { return this.duckTypingDeduce; } }
6,329
37.13253
189
java
depends
depends-master/src/main/java/depends/ParameterException.java
package depends; public class ParameterException extends Exception { public ParameterException(String message) { super( message); } private static final long serialVersionUID = 1L; }
191
16.454545
51
java
depends
depends-master/src/main/java/depends/addons/DV8MappingFileBuilder.java
/* MIT License Copyright (c) 2018-2019 Gang ZHANG Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package depends.addons; import java.io.File; import java.util.HashMap; import java.util.List; import java.util.Map; import com.fasterxml.jackson.databind.ObjectMapper; class MappingValue{ int family = 0; int vendor = 2; int type = 0; MappingValue(String orginalName, int typeId){ this.type = typeId; } public int getFamily() { return family; } public void setFamily(int family) { this.family = family; } public int getVendor() { return vendor; } public void setVendor(int vendor) { this.vendor = vendor; } public int getType() { return type; } public void setType(int type) { this.type = type; } } class MappingItem { String name; MappingValue id; public MappingItem(String dv8Name, int typeId) { this.name = dv8Name; String orginalName = dv8Name; this.id = new MappingValue(orginalName, typeId); } public String getName() { return name; } public void setName(String name) { this.name = name; } public MappingValue getId() { return id; } public void setId(MappingValue id) { this.id = id; } } public class DV8MappingFileBuilder { private List<String> supportedRelations; public DV8MappingFileBuilder(List<String> supportedRelations) { this.supportedRelations = supportedRelations; } public void create(String fileName) { Map<String,MappingItem> values = new HashMap<>(); for (int i=0;i<supportedRelations.size();i++) { String dep = supportedRelations.get(i); values.put(dep,new MappingItem(dep,i)); } ObjectMapper mapper = new ObjectMapper(); try { mapper.writerWithDefaultPrettyPrinter().writeValue(new File(fileName), values); } catch (Exception e) { e.printStackTrace(); } } }
2,813
25.299065
91
java
depends
depends-master/src/main/java/depends/entity/FunctionEntity.java
/* MIT License Copyright (c) 2018-2019 Gang ZHANG Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package depends.entity; import depends.relations.IBindingResolver; import java.util.ArrayList; import java.util.Collection; import java.util.List; public class FunctionEntity extends ContainerEntity{ private List<GenericName> returnTypeIdentifiers = new ArrayList<>(); Collection<VarEntity> parameters; Collection<GenericName> throwTypesIdentifiers = new ArrayList<>(); private Collection<Entity> returnTypes = new ArrayList<>(); private Collection<Entity> throwTypes = new ArrayList<>(); public FunctionEntity() { this.parameters = new ArrayList<>(); } public FunctionEntity(GenericName simpleName, Entity parent, Integer id, GenericName returnType) { super(simpleName, parent,id); this.returnTypes = new ArrayList<>(); returnTypeIdentifiers = new ArrayList<>(); this.parameters = new ArrayList<>(); throwTypesIdentifiers = new ArrayList<>(); addReturnType(returnType); } public Collection<Entity> getReturnTypes() { return returnTypes; } @Override public TypeEntity getType() { if (returnTypes.size()>0){ Object type = returnTypes.iterator().next(); if (type instanceof TypeEntity) return (TypeEntity)type; } return null; } public void addReturnType(GenericName returnType) { if (returnType==null) return; this.returnTypeIdentifiers.add(returnType); } public void addReturnType(TypeEntity returnType) { if (returnType==null) return; if (!this.returnTypeIdentifiers.contains(returnType.rawName)){ this.returnTypeIdentifiers.add(returnType.rawName); this.returnTypes.add(returnType); } } public void addThrowTypes(List<GenericName> throwedType) { throwTypesIdentifiers.addAll(throwedType); } @Override public void inferLocalLevelEntities(IBindingResolver bindingResolver) { for (VarEntity param:parameters) { param.fillCandidateTypes(bindingResolver); param.inferLocalLevelEntities(bindingResolver); } if (returnTypes.size()<returnTypeIdentifiers.size()) { returnTypes = identiferToEntities(bindingResolver,this.returnTypeIdentifiers); for ( GenericName returnTypeName: returnTypeIdentifiers) { Collection<Entity> typeEntities = typeParametersToEntities(bindingResolver, returnTypeName); this.appendTypeParameters(typeEntities); } } if (throwTypes.size()<throwTypesIdentifiers.size()) throwTypes = identiferToEntities(bindingResolver,this.throwTypesIdentifiers); super.inferLocalLevelEntities(bindingResolver); } private Collection<Entity> typeParametersToEntities(IBindingResolver bindingResolver, GenericName name) { ArrayList<Entity> r = new ArrayList<>(); for (GenericName typeParameter:name.getArguments()) { toEntityList(bindingResolver, r,typeParameter); } return r; } public Collection<VarEntity> getParameters() { return parameters; } public Collection<Entity> getThrowTypes() { return throwTypes; } @Override public Entity lookupVarInVisibleScope(GenericName varName) { for (VarEntity param:parameters) { if (varName.equals(param.getRawName())) { return param; } } return super.lookupVarInVisibleScope(varName); } public void addParameter(VarEntity var) { this.parameters.add(var); } @Override public String getDisplayName() { FileEntity f = (FileEntity) this.getAncestorOfType(FileEntity.class); return f.getRawName()+"("+this.getQualifiedName()+")"; } @Override public VarEntity lookupVarLocally(GenericName varName) { for (VarEntity var:this.parameters) { if (var.getRawName().equals(varName)) return var; } return super.lookupVarLocally(varName); } public void linkReturnToLastExpression() { if (expressionList()==null) return; for (int i = expressionList().size() - 1; i >= 0; i--) { Expression expr = expressionList().get(i); if (expr.isStatement()) expr.addDeducedTypeFunction(this); } } }
4,908
31.726667
106
java
depends
depends-master/src/main/java/depends/entity/Expression.java
/* MIT License Copyright (c) 2018-2019 Gang ZHANG Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package depends.entity; import depends.entity.repo.EntityRepo; import depends.relations.IBindingResolver; import java.io.Serializable; import java.util.ArrayList; import java.util.List; /** * Expression */ public class Expression implements Serializable{ private static final long serialVersionUID = 1L; public Integer id; private String text; // for debug purpose private GenericName rawType; // the raw type name private GenericName identifier; // the varName, or method name, etc. private boolean isSet = false; // is a set relation from right to leftHand private boolean isDot = false; // is a dot expression, will decuce variable tfype left to right private boolean isCall = false; private boolean isLogic = false; private boolean isCreate = false; private boolean isCast = false; private boolean isThrow = false; private boolean isStatement = false; //statement is only used for return type calcuation in some langs such as ruby //they will not be treat as real expressions in case of relation calculation private boolean deriveTypeFromChild = true; private Integer deduceTypeBasedId; //by default, parent expression type determined by most left child private Integer parentId = -1; private transient Expression parent; private transient List<VarEntity> deducedTypeVars = new ArrayList<>(); private List<Integer> deducedTypeVarsId = new ArrayList<>(); private transient List<FunctionEntity> deducedTypeFunctions= new ArrayList<>(); private List<Integer> deducedTypeFunctionsId = new ArrayList<>(); private Integer referredEntityId; private transient Entity referredEntity; private transient TypeEntity type; // the type we care - for relation calculation. private Location location = new Location(); //for leaf, it equals to referredEntity.getType. otherwise, depends on child's type strategy /* * */ public Expression() { deducedTypeVars = new ArrayList<>(); deducedTypeFunctions = new ArrayList<>(); } public Expression(Integer id) { this.id = id; deducedTypeVars = new ArrayList<>(); deducedTypeFunctions = new ArrayList<>(); } public void reload(EntityRepo repo, ArrayList<Expression> expressionList) { this.deducedTypeFunctions = new ArrayList<>(); this.deducedTypeVars = new ArrayList<>(); //recover parent relation if (parentId!=-1) { for (Expression expr:expressionList) { if (expr.id==parentId) { parent = expr; break; } } } //recover deducedTypeFunctionsId if (deducedTypeFunctionsId!=null) { for (Integer funcId:this.deducedTypeFunctionsId) { this.deducedTypeFunctions.add((FunctionEntity) repo.getEntity(funcId)); } } //recover deducedTypeVars if (deducedTypeVarsId!=null) { for (Integer varId:this.deducedTypeVarsId) { this.deducedTypeVars.add((VarEntity) repo.getEntity(varId)); } } //referer referredEntity -- TODO:maybe not require if (this.referredEntityId!=null && this.referredEntity==null) { this.referredEntity = repo.getEntity(this.referredEntityId); if (this.referredEntity ==null){ System.err.println("unexpected: referred Entity is null" + this.referredEntityId + this.text+this.id); } } } /** * Set type of the expression * if it is already has type, it will skip * if it is already referered entity, it will skip * if the type changed, parent expression will be re-caculated * For dynamic type language, return type or parameters, variables may depends on the expression type, * so once we get the type of expression, we will assign type to them. * * @param type the type of the expression * @param referredEntity the entity of the expression point to, which is used to calculate dependency relation * @param bindingResolver a parameter which will be passed to deduced parent type */ public void setType(TypeEntity type, Entity referredEntity, IBindingResolver bindingResolver) { if (this.getReferredEntity()==null && referredEntity!=null) { this.setReferredEntity(referredEntity); } boolean changedType = false; if (this.type==null && type!=null) { this.type = type; changedType = true; for (VarEntity var:deducedTypeVars) { if (var!=null) { var.setType(this.type); } } for (FunctionEntity func:deducedTypeFunctions) { if (func!=null) { func.addReturnType(this.type); } } } if (this.referredEntity==null) this.setReferredEntity(this.type); if (changedType) deduceTheParentType(bindingResolver); } /** * deduce type of parent based on child's type * * @param bindingResolver */ private void deduceTheParentType(IBindingResolver bindingResolver) { if (this.type==null) return; if (this.parent==null) return; Expression parent = this.parent; if (parent.type != null)return; if (!parent.deriveTypeFromChild) return; //parent's type depends on first child's type if (parent.deduceTypeBasedId!=this.id) return; //if child is a built-in/external type, then parent must also a built-in/external type if (this.type.equals(TypeEntity.buildInType)) { parent.setType(TypeEntity.buildInType,TypeEntity.buildInType, bindingResolver); return; } /* if it is a logic expression, the return type/type is boolean. */ if (parent.isLogic) { parent.setType(TypeEntity.buildInType,null, bindingResolver); } /* if it is a.b, and we already get a's type, b's type could be identified easily */ else if (parent.isDot) { if (parent.isCall()) { List<Entity> funcs = this.getType().lookupFunctionInVisibleScope(parent.identifier); parent.setReferredFunctions(bindingResolver, funcs); }else { Entity var = this.getType().lookupVarInVisibleScope(parent.identifier); if (var!=null) { parent.setType(var.getType(),var, bindingResolver); parent.setReferredEntity(var); }else { List<Entity> funcs = this.getType().lookupFunctionInVisibleScope(parent.identifier); parent.setReferredFunctions(bindingResolver,funcs); } } if (parent.getType()==null) { parent.setType(bindingResolver.inferTypeFromName(this.getType(), parent.identifier),null, bindingResolver); } } /* if other situation, simple make the parent and child type same */ else { parent.setType(type, null, bindingResolver); } if (parent.getReferredEntity()==null) parent.setReferredEntity(parent.type); } /** * set expr's referred entity to functions * why do not use 'setReferredEntity' directly? * in case of multiple functions, we should first construct a multi-declare entities object, * than set the type to multi-declare entity, for future resolver, * for example in duck typing case: * conn.send().foo, if conn is mutiple type (A, B), send should be search in both A and B * @param bindingResolver * @param funcs */ private void setReferredFunctions(IBindingResolver bindingResolver, List<Entity> funcs) { if (funcs ==null ||funcs.size()==0) return; Entity func = funcs.get(0); if (funcs.size()==1){ setType(func.getType(), func, bindingResolver); setReferredEntity(func); return; } MultiDeclareEntities m = new MultiDeclareEntities(func, bindingResolver.getRepo().generateId()); bindingResolver.getRepo().add(m); for (int i = 1; i< funcs.size(); i++) { m.add(funcs.get(i)); } setType(func.getType(), m, bindingResolver); setReferredEntity(m); } private void setReferredEntity(Entity referredEntity) { this.referredEntity = referredEntity; if (this.referredEntity!=null) { this.referredEntityId = referredEntity.getId(); } } /** * remember the vars depends on the expression type * @param var */ public void addDeducedTypeVar(VarEntity var) { this.deducedTypeVars.add(var); this.deducedTypeVarsId.add(var.getId()); } /** * remember the functions depends on the expression type * @param var */ public void addDeducedTypeFunction(FunctionEntity function) { this.deducedTypeFunctions.add(function); this.deducedTypeFunctionsId.add(function.id); } public void setParent(Expression parent) { this.parent = parent; if (parent!=null) this.parentId = parent.id; if (parent!=null) { if (parent.deduceTypeBasedId==null) parent.deduceTypeBasedId = id; if (parent.isSet) { parent.deduceTypeBasedId = id; } } } public GenericName getIdentifier() { return this.identifier; } public GenericName getRawType() { return this.rawType; } public void setIdentifier(String name) { if (!validName(name)){ return; } this.identifier = GenericName.build(name); } public void setIdentifier(GenericName name) { if (name==null) return; if (!validName(name.getName())){ return; } this.identifier = name; } public void setRawType(GenericName name) { if (name==null) return; if (!validName(name.getName())){ return; } this.rawType = name; } public void setRawType(String name) { if (name==null) return; if (!validName(name)){ return; } this.rawType = GenericName.build(name); } public Expression getParent() { return this.parent; } public void setText(String text) { this.text = text; } public boolean isCall() { return isCall; } public boolean isSet() { return isSet; } public void setSet(boolean isSet) { this.isSet = isSet; } public boolean isDot() { return isDot; } public void setDot(boolean isDot) { this.isDot = isDot; } public boolean isLogic() { return isLogic; } public void setLogic(boolean isLogic) { this.isLogic = isLogic; } public boolean isCreate() { return isCreate; } public void setCreate(boolean isCreate) { this.isCreate = isCreate; } public boolean isCast() { return isCast; } public void setCast(boolean isCast) { this.isCast = isCast; } public boolean isThrow() { return isThrow; } public void setThrow(boolean isThrow) { this.isThrow = isThrow; } public boolean isStatement() { return isStatement; } public void setStatement(boolean isStatement) { this.isStatement = isStatement; } public void setCall(boolean isCall) { this.isCall = isCall; } public void disableDriveTypeFromChild() { deriveTypeFromChild = false ; } public Entity getReferredEntity() { return referredEntity; } public TypeEntity getType() { return type; } private boolean validName(String name) { if (name==null) return false; if (name.toLowerCase().equals("<literal>")) return true; if (name.toLowerCase().equals("<built-in>")) return true; return true; } @Override public String toString() { StringBuilder s = new StringBuilder(); s.append("[").append(text).append("]").append("|") .append("rawType:").append(rawType).append("|") .append("identifier:").append(identifier).append("|") .append("prop:").append(isDot?"[dot]":"") .append(isSet?"[set]":"") .append(isLogic?"[bool]":"") .append(isCall?"[call]":"") .append(isCreate?"[new]":"") .append(isThrow?"[throw]":"").append("|") .append("parent:").append(parent==null?"nil":parent.text).append("|") .append("type:").append(type).append("|"); return s.toString(); } public void setLine(int lineNumber) { this.location.setLine(lineNumber); } public Location getLocation() { return location; } }
12,518
27.582192
116
java
depends
depends-master/src/main/java/depends/entity/ImportedFileCollector.java
/* MIT License Copyright (c) 2018-2019 Gang ZHANG Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package depends.entity; import java.util.HashSet; import java.util.Set; public class ImportedFileCollector { Set<FileEntity> checkedFiles = new HashSet<>(); Set<FileEntity> files = new HashSet<>(); public ImportedFileCollector(FileEntity fileEntity) { appendImportedFiles(fileEntity); } private void appendImportedFiles(FileEntity fileEntity) { if (checkedFiles.contains(fileEntity)) return; checkedFiles.add(fileEntity); files.add(fileEntity); for (Entity importedFile:fileEntity.getImportedFiles()) { if (importedFile instanceof FileEntity) { appendImportedFiles((FileEntity)importedFile); } } } public Set<FileEntity> getFiles() { return files; } }
1,769
31.777778
78
java
depends
depends-master/src/main/java/depends/entity/FunctionCall.java
/* MIT License Copyright (c) 2018-2019 Gang ZHANG Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package depends.entity; public class FunctionCall { private GenericName rawName; public FunctionCall(GenericName rawName){ this.rawName = rawName; } public GenericName getRawName() { return rawName; } }
1,292
34.916667
78
java
depends
depends-master/src/main/java/depends/entity/EntityNameBuilder.java
package depends.entity; public class EntityNameBuilder { public static String build(Entity entity) { return entity.getQualifiedName(); } }
144
17.125
44
java
depends
depends-master/src/main/java/depends/entity/PackageEntity.java
/* MIT License Copyright (c) 2018-2019 Gang ZHANG Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package depends.entity; import java.util.HashMap; import java.util.HashSet; public class PackageEntity extends TypeEntity { HashMap<String,Entity> entities = new HashMap<>(); public PackageEntity() {} public PackageEntity(String rawName, Integer id) { super(GenericName.build(rawName), null,id); setQualifiedName(rawName); //in Java, package raw name = full name } public PackageEntity(String rawName, Entity currentFile, Integer id) { super(GenericName.build(rawName), currentFile,id); } public Entity getChildOfName(String name) { for (Entity child:this.getChildren()) { if (child.getRawName().equals(name)) return child; } if (entities.get(name)!=null) return entities.get(name); return null; } public void addChild(String moduleName, Entity entity) { super.addChild(entity); entities.put(moduleName, entity); visibleNames.put(moduleName, entity); } @Override public Entity getByName(String name, HashSet<Entity> searched) { Entity entity = super.getByName(name, searched); if (entity!=null) return entity; for (Entity child:getChildren()) { if (child instanceof FileEntity) { if (searched.contains(child)) continue; entity = child.getByName(name,searched); if (entity!=null) return entity; } } return null; } }
2,383
30.368421
78
java
depends
depends-master/src/main/java/depends/entity/TypeEntity.java
/* MIT License Copyright (c) 2018-2019 Gang ZHANG Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package depends.entity; import depends.relations.IBindingResolver; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; public class TypeEntity extends ContainerEntity { static final public TypeEntity buildInType = new TypeEntity(GenericName.build("built-in"), null, -1); static final public TypeEntity genericParameterType = new TypeEntity(GenericName.build("T"), null, -3); Collection<TypeEntity> inheritedTypes = new ArrayList<>(); Collection<TypeEntity> implementedTypes = new ArrayList<>(); Collection<GenericName> inhertedTypeIdentifiers; Collection<GenericName> implementedIdentifiers; TypeEntity inheritedType; public TypeEntity() {} public TypeEntity(GenericName simpleName, Entity parent, Integer id) { super(simpleName, parent, id); inhertedTypeIdentifiers = new ArrayList<>(); implementedIdentifiers = new ArrayList<>(); } @Override public void inferLocalLevelEntities(IBindingResolver bindingResolver) { inheritedTypes = new ArrayList<>(); Collection<Entity> r = identiferToEntities(bindingResolver, this.inhertedTypeIdentifiers); if (r!=null) { r.forEach(item -> { Entity typeItem = getTypeEntity(item); if (typeItem !=null) { inheritedTypes.add((TypeEntity) typeItem); }else { System.err.println(item.getRawName() + " expected a type, but actually it is "+ item.getClass().getSimpleName()); } }); } inheritedTypes.remove(this); implementedTypes = new ArrayList<>(); r = identiferToEntities(bindingResolver, this.implementedIdentifiers); if (r!=null) { r.forEach(item -> { Entity typeItem = getTypeEntity(item); if (typeItem !=null) { implementedTypes.add((TypeEntity) typeItem); }else { System.err.println(item.getRawName() + " expected a type, but actually it is "+ item.getClass().getSimpleName()); } }); } implementedTypes.remove(this); if (inheritedTypes.size() > 0) inheritedType = inheritedTypes.iterator().next(); super.inferLocalLevelEntities(bindingResolver); } private Entity getTypeEntity(Entity item) { if (item==null) return null; if (item instanceof TypeEntity) return item; if (item instanceof MultiDeclareEntities) return ((MultiDeclareEntities)item).getType(); if (item instanceof AliasEntity) return item.getType(); return null; } public void addImplements(GenericName typeName) { if (typeName==null) { return; } if (typeName.equals(this.getRawName())) return; if (implementedIdentifiers.contains(typeName)) return; if (typeName.equals(this.rawName)) return; this.implementedIdentifiers.add(typeName); } public void addExtends(GenericName typeName) { if (typeName==null) { return; } if (typeName.equals(this.getRawName())) return; if (inhertedTypeIdentifiers.contains(typeName)) return; if (typeName.equals(this.rawName)) return; this.inhertedTypeIdentifiers.add(typeName); } public Collection<TypeEntity> getInheritedTypes() { return inheritedTypes; } public Collection<TypeEntity> getImplementedTypes() { return implementedTypes; } public TypeEntity getInheritedType() { return inheritedType; } @Override public FunctionEntity lookupFunctionLocally(GenericName functionName) { Collection<TypeEntity> searchedTypes = new ArrayList<>(); return lookupFunctionLocally(functionName,searchedTypes); } private FunctionEntity lookupFunctionLocally(GenericName functionName, Collection<TypeEntity> searched) { if (searched.contains(this)) return null; searched.add(this); FunctionEntity func = super.lookupFunctionLocally(functionName); if (func != null) return func; for (TypeEntity inhertedType : getInheritedTypes()) { func = inhertedType.lookupFunctionLocally(functionName, searched); if (func != null) break; } if (func != null) return func; for (TypeEntity implType : getImplementedTypes()) { func = implType.lookupFunctionLocally(functionName,searched); if (func != null) break; } return func; } @Override public VarEntity lookupVarLocally(GenericName varName) { Collection<TypeEntity> searchedTypes = new ArrayList<>(); return lookupVarLocally(varName,searchedTypes); } private VarEntity lookupVarLocally(GenericName varName, Collection<TypeEntity> searched) { if (searched.contains(this)) return null; searched.add(this); VarEntity var = super.lookupVarLocally(varName); if (var != null) return var; for (TypeEntity inhertedType : getInheritedTypes()) { var = inhertedType.lookupVarLocally(varName,searched); if (var != null) break; } if (var != null) return var; for (TypeEntity implType : getImplementedTypes()) { var = implType.lookupVarLocally(varName,searched); if (var != null) break; } return var; } @Override public TypeEntity getType() { return this; } @Override public Entity getByName(String name, HashSet<Entity> searched) { Entity entity = super.getByName(name, searched); if (entity!=null) return entity; for (TypeEntity child:getInheritedTypes()) { if (searched.contains(child)) continue; entity = child.getByName(name, searched); if (entity!=null) return entity; } for (TypeEntity child:getImplementedTypes()) { if (searched.contains(child)) continue; entity = child.getByName(name,searched); if (entity!=null) return entity; } return null; } }
6,473
30.580488
119
java
depends
depends-master/src/main/java/depends/entity/AliasEntity.java
/* MIT License Copyright (c) 2018-2019 Gang ZHANG Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package depends.entity; import depends.relations.IBindingResolver; import java.util.*; public class AliasEntity extends Entity { private Entity referToEntity = new EmptyTypeEntity(); private GenericName originName; private List<Entity> referPath = new ArrayList<>(); private boolean deepResolve = false; public AliasEntity() { } public AliasEntity(GenericName simpleName, Entity parent, Integer id, GenericName originTypeName) { super(simpleName, parent, id); this.originName = originTypeName; } public void inferLocalLevelEntities(IBindingResolver bindingResolver) { if (!(referToEntity instanceof EmptyTypeEntity)) return; Entity entity = bindingResolver.resolveName(this, originName, true); while(entity instanceof AliasEntity) { AliasEntity aliasEntity = (AliasEntity)entity; if (this.referPath.contains(aliasEntity)) { entity = null; break; } this.referPath.add(aliasEntity); entity = bindingResolver.resolveName(aliasEntity, aliasEntity.originName,true); if (entity==null) break; if (entity.equals(this)) { entity = null; break; } } if (entity != null) referToEntity = entity; } public Collection<Entity> getResolvedTypeParameters() { if (!(referToEntity instanceof DecoratedEntity)) return new ArrayList<>(); DecoratedEntity origin = (DecoratedEntity) referToEntity; return origin.getResolvedTypeParameters(); } public Collection<Entity> getResolvedAnnotations() { if (!(referToEntity instanceof DecoratedEntity)) return new ArrayList<>(); DecoratedEntity origin = (DecoratedEntity) referToEntity; return origin.getResolvedAnnotations(); } public ArrayList<VarEntity> getVars() { if (!(referToEntity instanceof ContainerEntity)) return new ArrayList<>(); ContainerEntity origin = (ContainerEntity) referToEntity; return origin.getVars(); } public ArrayList<FunctionEntity> getFunctions() { if (!(referToEntity instanceof ContainerEntity)) return new ArrayList<>(); ContainerEntity origin = (ContainerEntity) referToEntity; return origin.getFunctions(); } protected FunctionEntity lookupFunctionLocally(GenericName functionName) { if (!(referToEntity instanceof ContainerEntity)) return null; ContainerEntity origin = (ContainerEntity) referToEntity; return origin.lookupFunctionLocally(functionName); } public List<Entity> lookupFunctionInVisibleScope(GenericName functionName) { if (!(referToEntity instanceof ContainerEntity)) return null; ContainerEntity origin = (ContainerEntity) referToEntity; return origin.lookupFunctionInVisibleScope(functionName); } public Entity lookupVarsInVisibleScope(GenericName varName) { if (!(referToEntity instanceof ContainerEntity)) return null; ContainerEntity origin = (ContainerEntity) referToEntity; return origin.lookupVarInVisibleScope(varName); } public Collection<ContainerEntity> getResolvedMixins() { if (!(referToEntity instanceof ContainerEntity)) return new ArrayList<>(); ContainerEntity origin = (ContainerEntity) referToEntity; return origin.getResolvedMixins(); } public Collection<TypeEntity> getInheritedTypes() { if (referToEntity instanceof TypeEntity) return ((TypeEntity) referToEntity).getInheritedTypes(); return new ArrayList<>(); } public Collection<TypeEntity> getImplementedTypes() { if (referToEntity instanceof TypeEntity) return ((TypeEntity) referToEntity).getImplementedTypes(); return new ArrayList<>(); } public TypeEntity getInheritedType() { if (referToEntity instanceof TypeEntity) return ((TypeEntity) referToEntity).getInheritedType(); return null; } public Collection<Entity> getReturnTypes() { if (!(referToEntity instanceof FunctionEntity)) return new ArrayList<>(); FunctionEntity origin = (FunctionEntity) referToEntity; return origin.getReturnTypes(); } public TypeEntity getType() { return referToEntity.getType(); } public Collection<VarEntity> getParameters() { if (!(referToEntity instanceof FunctionEntity)) return new ArrayList<>(); FunctionEntity origin = (FunctionEntity) referToEntity; return origin.getParameters(); } public Collection<Entity> getThrowTypes() { if (!(referToEntity instanceof FunctionEntity)) return new ArrayList<>(); FunctionEntity origin = (FunctionEntity) referToEntity; return origin.getThrowTypes(); } public Entity getOriginType() { return referToEntity; } public Entity getReferToEntity() { return referToEntity; } public void setReferToEntity(Entity referToEntity) { this.referToEntity = referToEntity; } public Entity deepResolve() { if (!deepResolve) return this; Set<Entity> searched = new HashSet<>(); int i=0; Entity current = this; while(i<100) { //maximum 100 levels if (searched.contains(current)) return current; //avoid a loop if (!(current instanceof AliasEntity)) return current; searched.add(current); Entity originalFile = current.getAncestorOfType(FileEntity.class); current = ((AliasEntity)current).getReferToEntity(); if (current ==null) return this; //if already out of current file, return current if (!current.getAncestorOfType(FileEntity.class).equals(originalFile)) { return current; } i++; } return current; } public boolean isDeepResolve() { return deepResolve; } public void setDeepResolve(boolean deepResolve) { this.deepResolve = deepResolve; } }
6,504
30.887255
100
java
depends
depends-master/src/main/java/depends/entity/EmptyTypeEntity.java
/* MIT License Copyright (c) 2018-2019 Gang ZHANG Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package depends.entity; public class EmptyTypeEntity extends TypeEntity { public EmptyTypeEntity() { super(GenericName.build(""), null, -1); } }
1,231
35.235294
78
java
depends
depends-master/src/main/java/depends/entity/VarEntity.java
/* MIT License Copyright (c) 2018-2019 Gang ZHANG Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package depends.entity; import depends.relations.IBindingResolver; import java.util.ArrayList; import java.util.List; public class VarEntity extends ContainerEntity { private GenericName rawType; private TypeEntity type; private List<FunctionCall> functionCalls; public VarEntity() { } public VarEntity(GenericName simpleName, GenericName rawType, Entity parent, int id) { super(simpleName, parent,id); this.rawType = rawType; } public void setRawType(GenericName rawType) { this.rawType =rawType; } public GenericName getRawType() { return rawType; } @Override public TypeEntity getType() { return type; } public void setType(TypeEntity type) { this.type = type; } @Override public void inferLocalLevelEntities(IBindingResolver bindingResolver) { super.inferLocalLevelEntities(bindingResolver); Entity entity = bindingResolver.resolveName(this, rawType, true); if (entity!=null) { this.setActualReferTo(entity); type = entity.getType(); if (type==null) { if (((ContainerEntity)getParent()).isGenericTypeParameter(rawType)) { type = TypeEntity.genericParameterType; } } } if (type==null) { fillCandidateTypes(bindingResolver); } } public List<FunctionCall> getCalledFunctions() { if (this.functionCalls!=null) return functionCalls; return new ArrayList<>(); } public void addFunctionCall(GenericName fname) { if (this.functionCalls==null) { functionCalls = new ArrayList<>(); } this.functionCalls.add(new FunctionCall(fname)); } public void fillCandidateTypes(IBindingResolver bindingResolver) { if (!bindingResolver.isEagerExpressionResolve()) return; if (type!=null && !(type instanceof CandidateTypes)) return ; //it is a strong type lang, do not need deduce candidate types if (functionCalls==null) return; if (functionCalls.size()==0) return; //no information avaliable for type deduction if (this.rawType==null) { List<TypeEntity> candidateTypes = bindingResolver.calculateCandidateTypes(this,this.functionCalls); if (candidateTypes.size()>0) { this.type = new CandidateTypes(candidateTypes, bindingResolver.getRepo().generateId()); bindingResolver.getRepo().add(this.type); } } } }
3,309
29.934579
126
java
depends
depends-master/src/main/java/depends/entity/DecoratedEntity.java
/* MIT License Copyright (c) 2018-2019 Gang ZHANG Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package depends.entity; import depends.relations.IBindingResolver; import java.util.ArrayList; import java.util.Collection; import java.util.List; public abstract class DecoratedEntity extends Entity{ private Collection<GenericName> annotations; private Collection<Entity> resolvedAnnotations; private Collection<Entity> resolvedTypeParameters; public DecoratedEntity() { } public DecoratedEntity(GenericName rawName, Entity parent, Integer id) { super(rawName, parent, id); } public void addAnnotation(GenericName name) { if(this.annotations==null) annotations = new ArrayList<>(); this.annotations.add(name); } public void addTypeParameter(List<GenericName> parameters) { this.getRawName().appendArguments(parameters); } public void addTypeParameter(GenericName parameter) { this.getRawName().appendArguments(parameter); } protected void appendTypeParameters(Collection<Entity> typeParameterEntities) { if (resolvedTypeParameters==null) resolvedTypeParameters = new ArrayList<>(); resolvedTypeParameters.addAll(typeParameterEntities); } /** * For all data in the class, infer their types. * Should be override in sub-classes */ public void inferLocalLevelEntities(IBindingResolver bindingResolver) { Collection<Entity> typeParameterEntities = typeParametersToEntities(bindingResolver); appendTypeParameters(typeParameterEntities); // if (this.getAncestorOfType(FileEntity.class).getRawName().contains("/examples/usersession/server.py") // ) { // System.out.print("dd"); // } resolvedAnnotations = identiferToEntities(bindingResolver, annotations); } private Collection<Entity> typeParametersToEntities(IBindingResolver bindingResolver) { ArrayList<Entity> r = new ArrayList<>(); for (GenericName typeParameter:this.getRawName().getArguments()) { toEntityList(bindingResolver, r,typeParameter); } return r; } protected void toEntityList(IBindingResolver bindingResolver, ArrayList<Entity> r, GenericName typeParameter) { Entity entity = resolveEntity(bindingResolver, typeParameter); if (entity != null) r.add(entity); for (GenericName arg: typeParameter.getArguments()) { toEntityList(bindingResolver,r,arg); } } public Collection<Entity> getResolvedTypeParameters() { if (resolvedTypeParameters==null) return new ArrayList<>(); return resolvedTypeParameters; } public Collection<Entity> getResolvedAnnotations() { if (resolvedAnnotations==null) return new ArrayList<>(); return resolvedAnnotations; } public boolean isGenericTypeParameter(GenericName rawType) { boolean foundInCurrentLevel = rawType.find(rawType); if (foundInCurrentLevel) return true; if (this.getParent()==null || !(this.getParent() instanceof ContainerEntity)) return false; return ((ContainerEntity)getParent()).isGenericTypeParameter(rawType); } /** * A common utility function used to transfer the identifiers * to types. * @param bindingResolver - the inferer object * @param identifiers - the identifiers will be translated * @return The translated Types */ protected Collection<Entity> identiferToEntities(IBindingResolver bindingResolver, Collection<GenericName> identifiers) { if (identifiers==null) return null; if (identifiers.size()==0) return null; ArrayList<Entity> r = new ArrayList<>(); for (GenericName name : identifiers) { Entity entity = resolveEntity(bindingResolver, name); if (entity != null) r.add(entity); } return r; } private Entity resolveEntity(IBindingResolver bindingResolver, GenericName name) { Entity entity = bindingResolver.resolveName(this, name, true); if (entity==null) { if (((ContainerEntity)getParent()).isGenericTypeParameter(name)) { entity = TypeEntity.genericParameterType; } } return entity; } }
4,901
31.899329
122
java
depends
depends-master/src/main/java/depends/entity/Entity.java
/* MIT License Copyright (c) 2018-2019 Gang ZHANG Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package depends.entity; import depends.relations.IBindingResolver; import depends.relations.Relation; import java.util.*; /** * Entity is the root of all entities, including file, package, module, * class, method/function etc. * Each entity has unique id, name,qualifiedName, parent, children * We also use entity to record relations */ public abstract class Entity { Integer id=-1; String qualifiedName = null; GenericName rawName = GenericName.build(""); Entity parent; private MultiDeclareEntities mutliDeclare = null; private Set<Entity> children; ArrayList<Relation> relations; private Entity actualReferTo = null; private boolean inScope = true; protected HashMap<String, Entity> visibleNames = new HashMap<>(); private Location location = new Location(); public Entity() {}; public Entity(GenericName rawName, Entity parent, Integer id) { this.qualifiedName = null; this.rawName = rawName; this.parent = parent; this.id = id; if (parent!=null) parent.addChild(this); deduceQualifiedName(); visibleNames.put(rawName.getName(), this); visibleNames.put(qualifiedName, this); } private Set<Entity> children() { if (children==null) children = new HashSet<>(); return children; } /** * Rule 1: if it start with '.' , then the name is equal to raw name * Rule 2: if parent not exists, the name is equal to raw name * Rule 3: if parent exists but no qualified name exists or empty, the name is equal to raw name * Rule 4: otherwise, qualified name = parent_qualfied_name + "."+rawName * Rule 5: make sure the qualified name do not start with '.' */ private void deduceQualifiedName() { rawName = rawName.replace("::","." ); if (this.rawName.startsWith(".")) { this.qualifiedName = this.rawName.uniqName().substring(1); return; //already qualified } if (parent==null) { this.qualifiedName = this.rawName.uniqName(); return; } if (parent.getQualifiedName(true)==null) { this.qualifiedName = this.rawName.uniqName(); return; } if (parent.getQualifiedName(true).isEmpty()) { this.qualifiedName = rawName.uniqName(); return; } this.qualifiedName= parent.getQualifiedName(true)+"." + rawName.uniqName(); } public GenericName getRawName() { return rawName; } public Integer getId() { return id; } public void addRelation(Relation relation) { if (relations==null) relations = new ArrayList<>(); if (relation.getEntity()==null) return; relations.add(relation); } public ArrayList<Relation> getRelations() { if (relations==null) return new ArrayList<>(); return relations; } public void addChild(Entity child) { children().add(child); visibleNames.put(child.getRawName().getName(), child); visibleNames.put(child.getQualifiedName(), child); } public Entity getParent() { return parent; } public void setParent(Entity parent) { this.parent = parent; } public Collection<Entity> getChildren() { if (children==null) return new HashSet<>(); return children; } public void setQualifiedName(String qualifiedName) { this.qualifiedName = qualifiedName; } public void setRawName(GenericName rawName) { this.rawName = rawName; deduceQualifiedName(); } public String getQualifiedName() { return qualifiedName; } public String getQualifiedName(boolean overrideFileWithPackage) { return qualifiedName; } @Override public String toString() { return "Entity [id=" + id + ", qualifiedName=" + qualifiedName + ", rawName=" + rawName + "]"; } /** * Get ancestor of type. * @param classType * @return null (if not exist) or the type */ public Entity getAncestorOfType(@SuppressWarnings("rawtypes") Class classType) { Entity fromEntity = this; while(fromEntity!=null) { if (fromEntity.getClass().equals(classType)) return fromEntity; if (fromEntity.getParent()==null) return null; fromEntity = fromEntity.getParent(); } return null; } /** * Invoke inferer to resolve the entity type etc. * */ public void inferEntities(IBindingResolver bindingResolver) { inferLocalLevelEntities(bindingResolver); for (Entity child:this.getChildren()) { child.inferEntities(bindingResolver); } } public abstract void inferLocalLevelEntities(IBindingResolver bindingResolver); public TypeEntity getType() { return null; } public String getDisplayName() { return getRawName().uniqName(); } public MultiDeclareEntities getMutliDeclare() { return mutliDeclare; } public void setMutliDeclare(MultiDeclareEntities mutliDeclare) { this.mutliDeclare = mutliDeclare; } public Entity getActualReferTo() { if (this.actualReferTo ==null) return this; return actualReferTo; } public void setActualReferTo(Entity actualReferTo) { this.actualReferTo = actualReferTo; } public static void setParent(Entity child, Entity parent) { if (parent == null) return; if (child == null) return; if (parent.equals(child.getParent())) return; child.setParent(parent); parent.addChild(child); } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Entity other = (Entity) obj; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; return true; } public void setInScope(boolean value) { this.inScope = value; children().forEach(child->child.setInScope(value)); } public boolean inScope() { return inScope; } public Entity getByName(String name, HashSet<Entity> searched) { if (searched.contains(this)) return null; searched.add(this); return visibleNames.get(name); } public Integer getLine() { return location.getLine(); } public void setLine(int lineNumber) { this.location.setLine(lineNumber); } public Location getLocation() { return this.location; } }
7,259
25.304348
100
java