Compare commits

..

201 Commits

Author SHA1 Message Date
Till Schnell
26ae463e96 Improve to SC generation 2021-08-30 18:37:14 +02:00
Till Schnell
2e1e69df9a correct naming 2021-07-24 15:39:05 +02:00
Till Schnell
0e8012c132 resolved the todo 2021-06-11 23:26:25 +02:00
Till Schnell
68394565b5 correct typo 2021-06-02 11:00:52 +02:00
Till Schnell
c3b17a8f2f Add git ignore 2021-05-27 12:16:18 +02:00
JanUlrich
423cf8b9d2 Fix Object has null Constructor 2021-05-27 12:09:46 +02:00
JanUlrich
87fb9e5a33 merge 2021-05-27 11:46:32 +02:00
Till Schnell
df6debec4f Merge branch 'inferWildcards' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into inferWildcards 2021-05-26 21:20:51 +02:00
Till Schnell
59177e09ad add 2021-05-26 21:19:51 +02:00
Till Schnell
a9281a0db2 add filter for stuff in ast 2021-05-26 21:19:39 +02:00
Till Schnell
fe36b34a80 Add tests for source code gen 2021-05-26 20:59:25 +02:00
Till Schnell
d3a18887c3 ignore test output 2021-05-26 20:58:29 +02:00
Till Schnell
14821575bd Add implementation of source code manipulation 2021-05-26 20:57:14 +02:00
JanUlrich
c1519783ba Merge branch 'bigRefactoring' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into inferWildcards 2021-05-25 15:45:32 +02:00
JanUlrich
53bbf3c511 Merge bigRefactoring 2021-05-25 15:45:23 +02:00
pl@gohorb.ba-horb.de
48964d57ad 2
new file:   README_aktuelle_Branches
	modified:   src/main/java/de/dhbwstuttgart/syntaxtree/type/GenericRefType.java
	modified:   src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
2021-05-25 15:32:11 +02:00
JanUlrich
41492e53ca Modify Testcase for Unresolved Constraint Exception 2021-05-21 10:24:43 +02:00
pl@gohorb.ba-horb.de
18d9edfeea modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java
new file:   src/test/java/insertGenerics/TestVectorArg.java
	modified:   src/test/resources/bytecode/javFiles/Fac.jav
	new file:   src/test/resources/insertGenericsJav/TestVectorArg.jav
2021-05-21 09:52:22 +02:00
Till Schnell
74b9b024ee Reformat 2021-05-20 11:58:07 +02:00
Till Schnell
97483714e7 Add example for lib function 2021-05-20 11:46:50 +02:00
Till Schnell
a7b9c2a4ee Add generate BC Code Test 2021-05-10 18:10:19 +02:00
Till Schnell
fd7628cb40 Simplify generateConstraints 2021-05-10 18:02:23 +02:00
Till Schnell
76a291ab41 Fixed a Bug for a null Pointer Exception 2021-05-01 14:38:44 +02:00
Till Schnell
c5c8ffeed1 Correct gernation of oder constraints 2021-04-27 17:54:31 +02:00
Till Schnell
ba9335e2f6 Correct matcher 2021-04-27 17:54:10 +02:00
Till Schnell
c098a0a1b0 extract duplicate code to a separate method 2021-04-25 11:34:25 +02:00
Till Schnell
cfce2f55ac Add generation of wildcard constraints for generic types in source 2021-04-25 11:23:12 +02:00
Till Schnell
4009a28333 add expected type infer results. Enables gernation of bytecode 2021-04-24 14:14:19 +02:00
pl@gohorb.ba-horb.de
1b9e824b86 modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java
modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
2021-04-19 16:18:31 +02:00
pl@gohorb.ba-horb.de
b40cb49b9f In PairTPHsmallerTPH origPair eingefuegt, was das OriginalPair darstellt,
entweder vor oder waehrend der Unikation

	modified:   src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java
	new file:   src/main/java/de/dhbwstuttgart/typeinference/result/PairNoResult.java
noetig da als oriPairs auch Paare nicht solved form vorkommen koennen

	modified:   src/main/java/de/dhbwstuttgart/typeinference/result/PairTPHsmallerTPH.java
	modified:   src/main/java/de/dhbwstuttgart/typeinference/result/ResultPairVisitor.java
2021-04-19 14:22:40 +02:00
Till Schnell
f3dc0cbeb7 Add diamond expression 2021-04-16 19:34:49 +02:00
Till Schnell
cd2f030ac6 remove unused testcase 2021-04-14 10:50:01 +02:00
Till Schnell
f548548788 Add test case for param types 2021-04-14 10:48:40 +02:00
Till Schnell
5cf41101bf Only replace refType occurs in MethodReturn, Parameter, Field and Local
Var
2021-04-14 10:18:56 +02:00
Till Schnell
e139f8c867 Add Test for Void 2021-04-14 10:18:15 +02:00
Till Schnell
5a151a965c Add new test classes 2021-04-13 11:57:10 +02:00
pl@gohorb.ba-horb.de
be9ee49878 modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java
modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
	modified:   src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java
	modified:   src/main/java/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java
	modified:   src/main/java/de/dhbwstuttgart/syntaxtree/statement/Statement.java
	modified:   src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java
	modified:   src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
	modified:   src/test/java/insertGenerics/TestLocalVarLambda.java
2021-04-13 10:03:48 +02:00
Till Schnell
e5f03369cc Test via assert of amount of generated constraints 2021-04-13 09:14:17 +02:00
Till Schnell
f698c967c0 Delete outdated test class 2021-04-10 11:24:02 +02:00
Till Schnell
1509e21214 Add Test for MapNested 2021-04-10 11:23:34 +02:00
Till Schnell
50c05064c7 Add Test for map 2021-04-10 11:22:38 +02:00
Till Schnell
6458a06293 Add Test for nested 2021-04-10 11:21:49 +02:00
Till Schnell
a984e455e4 Add Test for single 2021-04-10 11:20:36 +02:00
Till Schnell
19c9f648a8 Add Testclass for fields 2021-04-10 11:19:15 +02:00
Till Schnell
077bd62b92 Introduce ? extends to the map of TPH. This should prevent an editing 2021-04-10 11:09:16 +02:00
Till Schnell
de62df00e0 correct test oputput 2021-04-10 10:42:58 +02:00
Till Schnell
78e3b76dc3 make test functions static 2021-04-10 10:42:28 +02:00
Till Schnell
c627f9de60 Split the single testcase to two 2021-04-10 10:40:58 +02:00
Till Schnell
ff92807b83 Add JavaDoc 2021-04-10 10:33:46 +02:00
Till Schnell
1043b3f55f remove a test 2021-04-09 20:31:40 +02:00
Till Schnell
88440b873a extract generation and merge to a static utility function 2021-04-09 20:25:10 +02:00
Till Schnell
4ca0e1e5f6 Add a child class of the compiler to implement the wildcard infer
algorithm
2021-04-09 20:13:15 +02:00
Till Schnell
cb28405fe1 made foreach over map not entry set 2021-04-09 20:04:58 +02:00
pl@gohorb.ba-horb.de
3363037854 modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java
modified:   src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java
	modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
	modified:   src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java
Neue Methode addTph

	modified:   src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java
Methodcall-Steatements mit Void als Returntyp
2021-04-09 09:15:10 +02:00
Till Schnell
c7f91724a6 remove rawtypes 2021-04-08 18:54:16 +02:00
Till Schnell
11b63e0a5d remove raw types and add java doc 2021-04-08 18:52:33 +02:00
Till Schnell
5f7829191c Improve log of test 2021-04-08 18:45:14 +02:00
Till Schnell
044d9a1860 improve log of replacement of tph 2021-04-08 18:37:42 +02:00
Till Schnell
6fcbca1187 remove useless imports 2021-04-08 18:31:14 +02:00
Till Schnell
572f41ffd4 Add tests for different classes 2021-04-08 18:31:02 +02:00
Till Schnell
e0f7f95bed remove unused test rsrc 2021-04-08 18:17:02 +02:00
Till Schnell
78c365a7be Add testclass for single wildcard test 2021-04-08 18:16:52 +02:00
Till Schnell
bea072689b Fix bug in test class 2021-04-08 18:08:54 +02:00
Till Schnell
81697eee64 Add iteration and replacement of nested type parameters 2021-04-08 18:08:38 +02:00
Till Schnell
c474abd2bd add test for nested types 2021-04-08 18:01:52 +02:00
Till Schnell
6dd02a654b Add JavaDoc 2021-04-08 17:57:41 +02:00
Till Schnell
e5d5376ce9 remove test case of the old approche 2021-04-08 11:30:49 +02:00
Till Schnell
0cdeee9e0d add combination of constraints 2021-04-08 11:30:07 +02:00
pl@gohorb.ba-horb.de
c8d4301e5e modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java
Alis Ansatz zur Bytecodeerzeugung eingesetzt

	modified:   src/main/java/de/dhbwstuttgart/bytecode/genericsGeneratorTypes/MethodAndConstraints.java
ToString ausprogramnmiert

	modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
Einige bytecode-Usecases laufen noch nicht (z.B. Put.jav) Erste Ansaetze versucht.
Muss noch erweitert werden.
2021-04-08 09:56:49 +02:00
Till Schnell
98b3ad1517 add replacement of param types with tph and generate consolidated
constraints
2021-04-06 18:44:30 +02:00
Till Schnell
b59aabeea5 generate the constraints for all tph 2021-04-06 18:38:01 +02:00
Till Schnell
26953665c9 search for all generics in ast 2021-04-06 18:26:10 +02:00
Till Schnell
465f82e967 Add generation of constraints for ref type 2021-04-06 18:25:04 +02:00
Till Schnell
ce8b19acae Remove visitors for the Oracle AST approche 2021-04-06 18:24:47 +02:00
Till Schnell
7dfe546999 return the source files 2021-04-06 18:24:05 +02:00
Till Schnell
c96c56e882 add comments 2021-04-06 17:23:04 +02:00
Till Schnell
3e57a64f9c add comment 2021-04-06 17:22:27 +02:00
Till Schnell
e8539a84fd Add array constructor 2021-04-04 15:40:16 +02:00
Till Schnell
0551d25fbf Add test for JavaTX constraints generation 2021-04-04 15:39:57 +02:00
pl@gohorb.ba-horb.de
b46415e45a modified: src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java
reset Typevars-Namen wieder rausgenommen

	modified:   src/main/java/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java

	modified:   src/test/java/insertGenerics/TestAny.java
	modified:   src/test/java/insertGenerics/TestClassField.java
	modified:   src/test/java/insertGenerics/TestContraVariant.java
	modified:   src/test/java/insertGenerics/TestGGFinder.java
	modified:   src/test/java/insertGenerics/TestLocalVarLambda.java
	modified:   src/test/java/insertGenerics/TestMutualRecursion.java
	modified:   src/test/java/insertGenerics/TestReturnVar.java
	modified:   src/test/java/insertGenerics/TestSecondLineOfClassConstraints.java
	modified:   src/test/java/insertGenerics/TestTPHsAndGenerics.java
	modified:   src/test/java/insertGenerics/TestTPHsAndGenerics2.java
	modified:   src/test/java/insertGenerics/TestThreeArgs.java
	modified:   src/test/java/insertGenerics/TestTwoArgs.java
	modified:   src/test/java/insertGenerics/TestTwoArgs2.java
	modified:   src/test/java/insertGenerics/TestTwoCalls.java
	modified:   src/test/java/insertGenerics/TestVector.java
	modified:   src/test/java/insertGenerics/TestVoidMeth.java
Reset Typevar-Namen in @BeforeClass eingefuegt
2021-04-01 19:16:57 +02:00
pl@gohorb.ba-horb.de
bbfd8aa203 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-04-01 17:13:06 +02:00
pl@gohorb.ba-horb.de
0cb1f244bc modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
Tests insertGenerics funtionieren
	modified:   src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java
	modified:   src/main/java/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java
reset-Funktion eingefuegt, damit bei jedem Test die Namen der TypepLaceholdert von vorne beginnen

	modified:   src/test/java/insertGenerics/TestContraVariant.java
	modified:   src/test/java/insertGenerics/TestTPHsAndGenerics.java
	modified:   src/test/java/insertGenerics/TestThreeArgs.java
2021-04-01 16:59:14 +02:00
pl@gohorb.ba-horb.de
9be64e4905 modified: src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java
modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
	modified:   src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java
	modified:   src/test/java/insertGenerics/TestContraVariant.java
	modified:   src/test/java/insertGenerics/TestLocalVarLambda.java
	modified:   src/test/java/insertGenerics/TestTransitiveClosure.java
Transitiv Closure auf new umgestellt
2021-03-31 18:18:16 +02:00
pl@gohorb.ba-horb.de
d1ad6e218a modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
modified:   src/test/java/insertGenerics/TestTwoArgs.java
2021-03-29 10:45:21 +02:00
pl@gohorb.ba-horb.de
bf8d4fe647 new file: src/test/resources/insertGenericsJav/TestContraVariant.jav
new file:   src/test/resources/insertGenericsJav/TestMutualRecursionWithField2.jav
	new file:   src/test/resources/insertGenericsJav/TestMutualRecursionWithField3.jav
2021-03-29 10:00:04 +02:00
pl@gohorb.ba-horb.de
e229093017 new file: src/test/java/insertGenerics/TestContraVariant.java
modified:   src/test/java/insertGenerics/TestTPHsAndGenerics.java
	new file:   src/test/java/insertGenerics/TestThreeArgs.java
2021-03-29 09:57:45 +02:00
Till Schnell
cbe2d7b0f5 extract test of unit 2021-03-27 18:06:28 +01:00
Till Schnell
59b45b5f87 Add test method 2021-03-27 18:04:28 +01:00
Till Schnell
ad7e7ec42b Add the placeholder mapping 2021-03-27 18:01:28 +01:00
Till Schnell
9d2c85d686 add get of constraints 2021-03-27 17:40:01 +01:00
Till Schnell
63b4dbcc10 correct test methods visibility 2021-03-27 17:39:42 +01:00
Till Schnell
ca816fba85 Add JavaCompiler parsing 2021-03-27 17:29:37 +01:00
pl@gohorb.ba-horb.de
66a25a56c0 Merge branch 'bytecodeGenericsSecond' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecodeGenericsSecond 2021-03-26 20:55:25 +01:00
AluAli
af223a4d8a modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-03-26 20:53:24 +01:00
pl@gohorb.ba-horb.de
14cb2c8909 Merge branch 'bytecodeGenericsSecond' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecodeGenericsSecond 2021-03-26 20:19:16 +01:00
AluAli
080eb2f6f3 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-03-26 20:18:45 +01:00
pl@gohorb.ba-horb.de
d8876457db Merge branch 'bytecodeGenericsSecond' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecodeGenericsSecond 2021-03-26 20:07:48 +01:00
AluAli
32e9ce92a6 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
modified:   src/test/java/insertGenerics/TestTwoArgs.java
2021-03-26 19:58:38 +01:00
pl@gohorb.ba-horb.de
3ad9007336 Merge branch 'bytecodeGenericsSecond' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecodeGenericsSecond 2021-03-26 19:27:33 +01:00
AluAli
da2a17c794 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
modified:   src/test/java/insertGenerics/TestTPHsAndGenerics.java
2021-03-26 18:33:36 +01:00
pl@gohorb.ba-horb.de
345b03b775 modified: src/test/java/insertGenerics/TestTPHsAndGenerics.java 2021-03-26 17:27:27 +01:00
pl@gohorb.ba-horb.de
ff93b0967e 2
modified:   src/test/java/insertGenerics/TestTPHsAndGenerics.java
2021-03-26 16:27:24 +01:00
pl@gohorb.ba-horb.de
db149eb588 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
klein Korrekturen

	modified:   src/test/java/insertGenerics/TestTwoArgs2.java
List -> Set
2021-03-26 16:15:18 +01:00
AluAli
f5f639c0f7 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-03-26 15:24:15 +01:00
AluAli
a4c38b2bb0 Merge branch 'bytecodeGenericsSecond' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecodeGenericsSecond 2021-03-26 12:30:13 +01:00
AluAli
e3625cb306 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
modified:   src/test/java/insertGenerics/TestTwoCalls.java
2021-03-26 12:29:40 +01:00
pl@gohorb.ba-horb.de
86603ae343 modified: src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java
equals korrigiert

	modified:   src/test/java/insertGenerics/TestGGFinder.java
	modified:   src/test/java/insertGenerics/TestLocalVarLambda.java
	modified:   src/test/java/insertGenerics/TestMutualRecursion.java
	modified:   src/test/java/insertGenerics/TestTPHsAndGenerics.java
	modified:   src/test/java/insertGenerics/TestTwoArgs.java
	modified:   src/test/java/insertGenerics/TestTwoCalls.java
	modified:   src/test/java/insertGenerics/TestVector.java
List -> Set vollendet
2021-03-26 10:51:59 +01:00
pl@gohorb.ba-horb.de
d276c7c044 modified: src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java
modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/ClassConstraint.java
	modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
toString wieder korrigiert

	modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/MethodConstraint.java
	modified:   src/test/java/insertGenerics/TestAny.java
List -> Set
Bei allen anderen Tests fehlt es noch
2021-03-25 19:55:16 +01:00
pl@gohorb.ba-horb.de
91c075829b Merge branch 'generateTestConstraints' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecodeGenericsSecond 2021-03-25 18:59:34 +01:00
pl@gohorb.ba-horb.de
705d0b6a73 renamed: src/test/java/insertGenerics/AllTests.java -> src/test/java/insertGenerics/TestMutualRecursion.java
modified:   src/test/java/insertGenerics/TestTPHsAndGenerics.java
	modified:   src/test/java/insertGenerics/TestVector.java
Tests angepasst an die GeneratedGenerics
2021-03-25 18:56:38 +01:00
pl@gohorb.ba-horb.de
bc378f2fe9 modified: src/test/java/insertGenerics/AllTests.java
modified:   src/test/java/insertGenerics/TestTwoCalls.java
	modified:   src/test/java/insertGenerics/TestVector.java
2021-03-25 00:41:03 +01:00
pl@gohorb.ba-horb.de
e5816bac22 modified: src/test/java/insertGenerics/TestAny.java
modified:   src/test/java/insertGenerics/TestGGFinder.java
	modified:   src/test/java/insertGenerics/TestLocalVarLambda.java
	modified:   src/test/java/insertGenerics/TestTPHsAndGenerics.java
	modified:   src/test/java/insertGenerics/TestTwoArgs.java
	modified:   src/test/java/insertGenerics/TestTwoArgs2.java
Tests fuer GeneratedGenerics eingefuegt
2021-03-24 11:35:15 +01:00
pl@gohorb.ba-horb.de
8c6027645f modified: src/test/java/insertGenerics/TestLocalVarLambda.java
Alternative Typvarnamen eingefuegt.
2021-03-24 10:22:57 +01:00
pl@gohorb.ba-horb.de
e147a8ce85 toString geaendert, um Tests generieren zu koennen:
modified:   src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java
	modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/ClassConstraint.java
	modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
	modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/MethodConstraint.java

geaendert, um GenerateGenerics direkt teste zu koennen, sollte ggf. wieder rueckgaenig gemacht werden
	modified:   src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java
	modified:   src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java

angepasset Tests:
	modified:   src/test/java/insertGenerics/TestLocalVarLambda.java
	modified:   src/test/java/insertGenerics/TestTPHsAndGenerics.java
	modified:   src/test/java/insertGenerics/TestTwoArgs.java
2021-03-23 12:02:58 +01:00
Till Schnell
54a2dbfedc add simple test 2021-03-22 17:47:35 +01:00
JanUlrich
07c1eeeb36 Recompile parser with ANTLR v4.8 2021-03-22 14:52:54 +01:00
AluAli
d08e598649 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-03-19 22:02:23 +01:00
AluAli
ba8df8b376 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-03-19 18:27:50 +01:00
AluAli
b147430fb6 kommentierte neue Regeln 2021-03-19 15:05:40 +01:00
AluAli
661fa53937 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-03-19 14:42:22 +01:00
AluAli
13144d0ac9 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-03-19 14:23:07 +01:00
AluAli
539cacef86 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-03-19 08:50:04 +01:00
JanUlrich
69a557f1f2 Fehlerhaften code entfernen 2021-03-18 11:39:07 +01:00
pl@gohorb.ba-horb.de
6e0e575524 new file: src/test/java/insertGenerics/TestLocalVarLambda.java 2021-03-15 11:27:31 +01:00
AluAli
55e44d62de modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-03-13 14:52:38 +01:00
AluAli
54de28c3f0 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-03-13 13:16:47 +01:00
AluAli
8e89c9b5e8 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-03-13 01:26:20 +01:00
AluAli
bb5692da8e modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-03-12 18:35:29 +01:00
pl@gohorb.ba-horb.de
f69554c6a1 equals in in Type eingefuegt 2021-03-12 18:29:51 +01:00
pl@gohorb.ba-horb.de
fbb7d82ef4 Merge branch 'bytecodeGenericsSecond' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecodeGenericsSecond 2021-03-12 18:22:03 +01:00
pl@gohorb.ba-horb.de
4f1aadef60 modified: src/main/java/de/dhbwstuttgart/syntaxtree/type/RefTypeOrTPHOrWildcardOrGeneric.java 2021-03-12 18:21:46 +01:00
AluAli
4acb820202 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-03-12 17:08:40 +01:00
pl@gohorb.ba-horb.de
6862c91b73 modified: src/main/java/de/dhbwstuttgart/bytecode/constraint/TPHConstraint.java 2021-03-12 12:30:41 +01:00
AluAli
55ee8ab61a modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-03-12 11:43:55 +01:00
AluAli
af9943be28 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-03-05 21:47:22 +01:00
AluAli
f208432c54 modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java
modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
2021-03-05 20:18:48 +01:00
pl@gohorb.ba-horb.de
2ca4aad07d modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java
modified:   src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java
2021-03-05 10:57:42 +01:00
AluAli
b99c022b50 modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java
modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
2021-03-05 09:12:19 +01:00
AluAli
d1a796f37b Merge branch 'bytecodeGenericsSecond' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecodeGenericsSecond 2021-03-05 00:32:33 +01:00
AluAli
31d7856afa modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java
modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
2021-03-05 00:31:36 +01:00
pl@gohorb.ba-horb.de
b711dc72e0 new file: src/test/java/insertGenerics/AllTests.java 2021-03-04 18:58:33 +01:00
AluAli
d14f1d92c9 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-02-26 11:42:31 +01:00
pl@gohorb.ba-horb.de
ebb0803a38 new file: ../../../java/insertGenerics/TestTwoCalls.java
new file:   ../../../java/insertGenerics/TestVector.java
	new file:   ../../insertGenericsJav/TestLocalVarLambda.jav
	new file:   ../../insertGenericsJav/TestMutualRecursion.jav
	new file:   ../../insertGenericsJav/TestMutualRecursionWithField.jav
	new file:   ../../insertGenericsJav/TestThreeArgs.jav
	new file:   ../../insertGenericsJav/TestTwoCalls.jav
	new file:   ../../insertGenericsJav/TestVector.jav
2021-02-25 15:59:24 +01:00
pl@gohorb.ba-horb.de
60f2e3def4 modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java
modified:   src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java
2021-02-25 00:13:29 +01:00
pl@gohorb.ba-horb.de
7e35e09c47 modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java
modified:   src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java
	modified:   src/main/java/de/dhbwstuttgart/syntaxtree/Method.java
	modified:   src/main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java
	modified:   src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java
AndConstraints einer Methode in Methode.java und iin MethodAndTPH.java eingefuegt
	modified:   src/test/resources/insertGenericsJav/TestAny.jav
2021-02-19 13:58:48 +01:00
pl@gohorb.ba-horb.de
ab99889c3c modified: src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
Bei Return SMALLERDOT durch EQUALSDOT ersetzt
2021-02-16 16:52:53 +01:00
pl@gohorb.ba-horb.de
bbdf220324 modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java
modified:   src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java
	modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
	modified:   src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java
	modified:   src/main/java/de/dhbwstuttgart/syntaxtree/Method.java
	modified:   src/main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java
	modified:   src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java
Pairs sammeln rueckgaengig gemacht
2021-02-16 16:27:17 +01:00
pl@gohorb.ba-horb.de
f2d6dae4c7 Letzer Stand mit Pair Bildug waehrend des Typvars sammeln 2021-02-16 15:29:24 +01:00
pl@gohorb.ba-horb.de
905dfd8a27 modified: ../../../../main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java
modified:   ../../../../main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
2021-02-08 00:15:25 +01:00
pl@gohorb.ba-horb.de
5fb2d57d3b modified: ../../../../main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java 2021-02-07 09:47:25 +01:00
pl@gohorb.ba-horb.de
5b7fec660d modified: ../../../../main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java 2021-02-06 09:51:42 +01:00
pl@gohorb.ba-horb.de
5980f1c7b8 modified: ../../../../main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java
modified:   ../../../../main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java
	modified:   ../../../../main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
	modified:   ../../../../main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java
	modified:   ../../../java/constraintSimplify/FamilyOfGenerics.java
	modified:   ../../../java/insertGenerics/TestTPHsAndGenerics.java
2021-02-05 22:37:39 +01:00
pl@gohorb.ba-horb.de
f270686b3c modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java
modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
	modified:   src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java
	modified:   src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java
	modified:   src/test/java/constraintSimplify/FamilyOfGenerics.java
2021-02-04 23:58:49 +01:00
pl@gohorb.ba-horb.de
92bc3d626c modified: ../../../../main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java
SourceFile und nameToMeth ergaenzt

	modified:   ../../../../main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java
	modified:   ../../../../main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java
	  List<Method> getAllMethods() ergaenzty

	modified:   ../../../../main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java
           variance wird uebernommen

	modified:   ../../../../main/java/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java
	   setVariance gefuegt.

	modified:   ../../../java/insertGenerics/TestTwoArgs.java
	modified:   ../../../java/insertGenerics/TestTwoArgs2.java
	modified:   ../../insertGenericsJav/TestTwoArgs.jav
	modified:   ../../insertGenericsJav/TestTwoArgs2.jav
2021-02-03 16:55:12 +01:00
pl@gohorb.ba-horb.de
ef723e4103 modified: ../../../../main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java
Zusaetzliche Typvariablen weider entfernt
2021-02-01 16:56:33 +01:00
AluAli
9f06118138 modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java
modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
2021-01-31 20:54:03 +01:00
AluAli
a0c92c2d9d Merge branch 'bytecodeGenericsSecond' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecodeGenericsSecond 2021-01-31 20:34:18 +01:00
pl@gohorb.ba-horb.de
c6d896fa3b modified: ../../../main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java
modified:   ../../java/insertGenerics/TestGGFinder.java
	modified:   TestGGFinder.jav
2021-01-30 22:06:27 +01:00
pl@gohorb.ba-horb.de
b942e508fc Merge branch 'bytecodeGenericsSecond' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecodeGenericsSecond 2021-01-29 22:49:07 +01:00
pl@gohorb.ba-horb.de
f33002e998 new file: src/test/java/insertGenerics/TestTwoArgs.java
new file:   src/test/resources/insertGenericsJav/TestTwoArgs.jav
2021-01-29 22:48:20 +01:00
AluAli
2dc4331afb modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java 2021-01-29 20:45:54 +01:00
AluAli
ebf6f0bbe3 modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java 2021-01-29 20:41:43 +01:00
AluAli
dc62b72f7f modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java
modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
2021-01-29 19:36:17 +01:00
AluAli
42bb787195 Merge branch 'bytecodeGenericsSecond' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecodeGenericsSecond 2021-01-29 18:22:39 +01:00
AluAli
cd135c3962 modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java 2021-01-29 18:22:04 +01:00
pl@gohorb.ba-horb.de
59adfd6c59 Merge branch 'bytecodeGenericsSecond' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecodeGenericsSecond 2021-01-29 18:13:09 +01:00
pl@gohorb.ba-horb.de
604300a07e modified: src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java
new file:   src/test/java/insertGenerics/TestTwoArgs.java
	new file:   src/test/java/insertGenerics/TestTwoArgs2.java
	new file:   src/test/resources/insertGenericsJav/TestTwoArgs.jav
	new file:   src/test/resources/insertGenericsJav/TestTwoArgs2.jav
2021-01-29 18:12:44 +01:00
AluAli
0bc0e4c722 modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java
deleted:    src/test/java/insertGenerics/MethodsTest.java
	deleted:    src/test/java/insertGenerics/TryTest.java
2021-01-29 18:03:43 +01:00
pl@gohorb.ba-horb.de
ebfc3dedbe Merge branch 'bytecodeGenericsSecond' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecodeGenericsSecond 2021-01-29 12:29:24 +01:00
pl@gohorb.ba-horb.de
e07e5e9b42 modified: src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java 2021-01-29 12:29:08 +01:00
AluAli
8fb7a23279 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
modified:   src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java
	modified:   src/test/java/insertGenerics/TestExample42.java
	modified:   src/test/java/insertGenerics/TestExample42_allInOneMethod.java
2021-01-29 12:24:16 +01:00
pl@gohorb.ba-horb.de
8706882388 modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java
new file:   src/test/java/insertGenerics/TestGGFinder.java
2021-01-29 10:55:04 +01:00
pl@gohorb.ba-horb.de
918d0db799 modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java 2021-01-29 09:25:10 +01:00
pl@gohorb.ba-horb.de
4b99b38b47 Merge branch 'bigRefactoringUnifyComment' into bytecodeGenericsSecond 2021-01-28 16:18:42 +01:00
pl@gohorb.ba-horb.de
1236ca2953 modified: src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java
modified:   src/test/resources/insertGenericsJav/TestGGFinder.jav
2021-01-28 16:12:17 +01:00
AluAli
1348a7a4b6 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-01-23 00:07:05 +01:00
AluAli
3f4aa7bbd5 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
modified:   src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java
	modified:   src/test/java/insertGenerics/TestExample42.java
	modified:   src/test/java/insertGenerics/TestExample42_allInOneMethod.java
2021-01-22 23:49:25 +01:00
AluAli
bb900af6bf modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-01-22 15:52:14 +01:00
AluAli
cfacc6235c modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-01-22 15:13:03 +01:00
AluAli
1a135ebe5c modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java
modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
2021-01-22 15:07:03 +01:00
AluAli
c15953bbac modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java 2021-01-18 19:15:36 +01:00
AluAli
404bbbf746 Merge branch 'bytecodeGenericsSecond' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecodeGenericsSecond 2021-01-18 19:11:33 +01:00
AluAli
a8f04a25cd modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java 2021-01-18 19:10:04 +01:00
pl@gohorb.ba-horb.de
1242252cde modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java 2021-01-18 13:46:06 +01:00
pl@gohorb.ba-horb.de
5e9e774d1e Merge branch 'bytecodeGenericsSecond' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecodeGenericsSecond 2021-01-18 13:41:44 +01:00
pl@gohorb.ba-horb.de
bd6d74c74d modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java 2021-01-18 13:40:20 +01:00
AluAli
3d8275c676 modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java 2021-01-16 16:34:31 +01:00
pl@gohorb.ba-horb.de
3ef15d814d Merge branch 'bytecodeGenericsSecond' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecodeGenericsSecond 2021-01-16 09:16:25 +01:00
pl@gohorb.ba-horb.de
842b85cfd7 modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java 2021-01-16 09:12:34 +01:00
AluAli
fc8f11ebb1 modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java
new file:   src/test/java/insertGenerics/TestAny.java
	new file:   src/test/java/insertGenerics/TestTPHsAndGenerics2.java
	new file:   src/test/resources/insertGenericsJav/TestAny.jav
	modified:   src/test/resources/insertGenericsJav/TestReturnVar.jav
	modified:   src/test/resources/insertGenericsJav/TestSecondLineOfClassConstraints.jav
	new file:   src/test/resources/insertGenericsJav/TestTPHsAndGenerics2.jav
2021-01-16 00:35:12 +01:00
AluAli
eb97dd810f modified: src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java
new file:   src/test/java/insertGenerics/TestClassField.java
	new file:   src/test/java/insertGenerics/TestReturnVar.java
	new file:   src/test/java/insertGenerics/TestSecondLineOfClassConstraints.java
	new file:   src/test/java/insertGenerics/TestTPHsAndGenerics.java
	new file:   src/test/java/insertGenerics/TestVoidMeth.java
	new file:   src/test/resources/insertGenericsJav/TestClassField.jav
	new file:   src/test/resources/insertGenericsJav/TestReturnVar.jav
	new file:   src/test/resources/insertGenericsJav/TestSecondLineOfClassConstraints.jav
	new file:   src/test/resources/insertGenericsJav/TestTPHsAndGenerics.jav
	new file:   src/test/resources/insertGenericsJav/TestVoidMeth.jav
2021-01-15 13:18:09 +01:00
AluAli
ab850edae8 modified: src/main/java/de/dhbwstuttgart/bytecode/genericsGenerator/GeneratedGenericsFinder.java 2021-01-15 01:12:13 +01:00
pl@gohorb.ba-horb.de
95f48ffcb7 modified: ../src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
ckeckA druch checkNoContradiction ersetzt
2021-01-14 15:29:06 +01:00
pl@gohorb.ba-horb.de
163f0f3047 modified: ../src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
vor Loeschung von checkA
2021-01-14 14:59:20 +01:00
pl@gohorb.ba-horb.de
1cf22d2602 modified: ../src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
remaingSet entfernt
fstElems in oneElems umbenannt
2021-01-14 11:27:19 +01:00
pl@gohorb.ba-horb.de
d8ac25234f modified: ../src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
vor entfernung von Remaining
2021-01-14 10:38:32 +01:00
pl@gohorb.ba-horb.de
e00d76ce3b Occurs-Check mit Abbruch eingebaut
finalResult zum Attribut der Klasse gemacht
2021-01-13 19:39:01 +01:00
pl@gohorb.ba-horb.de
fec83c3a62 modified: src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
Fuer den Receiver wieder = eingefuegt.

	modified:   src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
Kommentierung begonnen
2021-01-12 21:27:44 +01:00
AluAli
3f5f51df5b modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java 2021-01-08 22:05:09 +01:00
AluAli
dce7ac8262 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
new file:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/PairMethodAndConstraint.java
	modified:   src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java
2021-01-08 21:43:06 +01:00
AluAli
88175f8b48 modified: src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
modified:   src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java
	modified:   src/test/java/insertGenerics/TestExample42.java
2021-01-08 15:44:07 +01:00
125 changed files with 4855 additions and 2362 deletions

1
.gitignore vendored
View File

@@ -29,3 +29,4 @@ logFiles/**
src/main/java/de/dhbwstuttgart/parser/antlr/ src/main/java/de/dhbwstuttgart/parser/antlr/
src/main/java/de/dhbwstuttgart/sat/asp/parser/antlr/ src/main/java/de/dhbwstuttgart/sat/asp/parser/antlr/
/pull.sh

10
README_aktuelle_Branches Normal file
View File

@@ -0,0 +1,10 @@
Stand: 24.5.21
bigRefactoring: Master-Brach
bigRefactoringUnifyComment: Dokumentation Unify, Martin
bytecodeGenericsSecond: Generated Generics, Ali, Martin
inferWildcards, Wildcards, Till
master, derzeit nicht genutzt
plugin, eigemntlicher Branch fuer Plugin-Basis, derzeit nicht aktuelle (aktuelle Version in simplifyRes
simplifyRes, Basis fuer Plugin, sollte auf Plugin gemerged werden, noch keine Packages, Michael
strucTypesNew, Struturelle Typen, alte Basis, arbeite derzeit niemand

10
pom.xml
View File

@@ -118,15 +118,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
</descriptorRefs> </descriptorRefs>
</configuration> </configuration>
</plugin> </plugin>
<plugin> </plugins>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build> </build>
<repositories> <repositories>
<repository> <repository>

View File

@@ -10,6 +10,9 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint; import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
@@ -30,6 +33,9 @@ import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.GenericInsertPair; import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
import de.dhbwstuttgart.typeinference.result.ResultPair; import de.dhbwstuttgart.typeinference.result.ResultPair;
import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.result.ResultSet;
@@ -49,6 +55,10 @@ public class TPHExtractor extends AbstractASTWalker {
boolean inLocalOrParamOrReturn = false; boolean inLocalOrParamOrReturn = false;
public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>(); public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
// Alle Constraints in einer Menge (Und- & Oder-Constraints)
public Set<Pair> oldConstraints = new HashSet<>();
final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> allPairs = new ArrayList<>(); final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> allPairs = new ArrayList<>();
public final ArrayList<TPHConstraint> allCons = new ArrayList<>(); public final ArrayList<TPHConstraint> allCons = new ArrayList<>();
private ResultSet resultSet; private ResultSet resultSet;
@@ -78,15 +88,25 @@ public class TPHExtractor extends AbstractASTWalker {
public void visit(TypePlaceholder tph) { public void visit(TypePlaceholder tph) {
if (resultSet.resolveType(tph).resolvedType instanceof TypePlaceholder) { if (resultSet.resolveType(tph).resolvedType instanceof TypePlaceholder) {
TypePlaceholder resolvedTPH = (TypePlaceholder) resultSet.resolveType(tph).resolvedType; TypePlaceholder resolvedTPH = (TypePlaceholder) resultSet.resolveType(tph).resolvedType;
if (inMethod) { String tphName = resolvedTPH.getName();
methodAndTph.getTphs().add(resolvedTPH.getName()); if (inMethod && !tphsClass.contains(tphName)) {
if (inLocalOrParamOrReturn) ArrayList<String> tphs = null;
methodAndTph.getLocalTphs().add(resolvedTPH.getName()); if (!(tphs = methodAndTph.getTphs()).contains(tphName)) {
}else { methodAndTph.addTph(tphName);
tphsClass.add(resolvedTPH.getName()); }
if (inLocalOrParamOrReturn) {
if (!(tphs = methodAndTph.getLocalTphs()).contains(tphName)) {
tphs.add(tphName);
}
}
} else {
if (!tphsClass.contains(tphName)) {
tphsClass.add(tphName);
}
}
if (!allTPHS.containsKey(tphName)) {
allTPHS.put(tphName, inMethod);
} }
allTPHS.put(resolvedTPH.getName(), inMethod);
// final List<TPHConstraint> cons = new ArrayList<>(); // final List<TPHConstraint> cons = new ArrayList<>();
// resultSet.resolveType(tph).additionalGenerics.forEach(ag -> { // resultSet.resolveType(tph).additionalGenerics.forEach(ag -> {
// TPHConstraint con = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS); // TPHConstraint con = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
@@ -153,7 +173,7 @@ public class TPHExtractor extends AbstractASTWalker {
public void visit(GenericRefType genericRefType) { public void visit(GenericRefType genericRefType) {
String name = genericRefType.getParsedName(); String name = genericRefType.getParsedName();
if (inMethod) { if (inMethod) {
methodAndTph.getTphs().add(name); methodAndTph.addTph(name);
if (inLocalOrParamOrReturn) if (inLocalOrParamOrReturn)
methodAndTph.getLocalTphs().add(name); methodAndTph.getLocalTphs().add(name);
}else { }else {
@@ -175,7 +195,33 @@ public class TPHExtractor extends AbstractASTWalker {
public void visit(Method method) { public void visit(Method method) {
inMethod = true; inMethod = true;
String id = MethodUtility.createID(resolver,method); String id = MethodUtility.createID(resolver,method);
methodAndTph = new MethodAndTPH(id); Predicate<Pair> filterUndConstraints = cs -> ((cs.TA1 instanceof TypePlaceholder) && (cs.TA2 instanceof TypePlaceholder) &&
(resultSet.resolveType((TypePlaceholder)(cs.TA1)).resolvedType instanceof TypePlaceholder) &&
(resultSet.resolveType((TypePlaceholder)(cs.TA2)).resolvedType instanceof TypePlaceholder));
Function<ConstraintSet<Pair>, ConstraintSet<Pair>> filterConstrRemainingTVar =
csS -> {
ConstraintSet<Pair> ret = new ConstraintSet<>();
ret.addAllUndConstraint(
csS.getUndConstraints()
.stream().filter(filterUndConstraints)
.collect(Collectors.toCollection(Constraint<Pair>::new)));
csS.getOderConstraints()
.forEach(oConSSet -> { Set<Constraint<Pair>> setCons = new HashSet<>();
oConSSet.forEach(OConS -> { Constraint<Pair> newConsPair = new Constraint<Pair>();
newConsPair.isStatement = OConS.isStatement;
setCons.add(
OConS.stream()
.filter(filterUndConstraints)
.collect(Collectors.toCollection(() -> newConsPair)) );
} );
ret.addOderConstraint(setCons);} );
return ret;
};
ConstraintSet<Pair> filteredConstraints = filterConstrRemainingTVar.apply(method.getConstraints());
methodAndTph = new MethodAndTPH(id, filteredConstraints);
oldConstraints.addAll(filteredConstraints.getAll());
inLocalOrParamOrReturn = true; inLocalOrParamOrReturn = true;
method.getReturnType().accept(this); method.getReturnType().accept(this);
@@ -184,7 +230,7 @@ public class TPHExtractor extends AbstractASTWalker {
if(method.block != null) if(method.block != null)
method.block.accept(this); method.block.accept(this);
inMethod = false; inMethod = false;
ListOfMethodsAndTph.add(methodAndTph); ListOfMethodsAndTph.add(methodAndTph);
} }

View File

@@ -1,13 +1,25 @@
package de.dhbwstuttgart.bytecode.constraint; package de.dhbwstuttgart.bytecode.constraint;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
public class TPHConstraint { public class TPHConstraint {
protected String left; protected String left;
protected String right; protected String right;
protected Relation rel; protected Relation rel;
protected int variance; //noch nicht benutzt
public enum Relation{ public enum Relation{
EXTENDS, EQUAL EXTENDS, EQUAL
} }
public TPHConstraint(Pair p) {
this.left = ((TypePlaceholder)p.TA1).getName();
this.right = ((TypePlaceholder)p.TA2).getName();
this.rel = p.GetOperator().equals(PairOperator.SMALLERDOT) ? Relation.EXTENDS : Relation.EQUAL;
}
public TPHConstraint(String left, String right, Relation rel) { public TPHConstraint(String left, String right, Relation rel) {
this.left = left; this.left = left;
this.right = right; this.right = right;
@@ -48,6 +60,25 @@ public class TPHConstraint {
return rel == constraint.getRel() && left.equals(constraint.getLeft()) && right.equals(constraint.getRight()); return rel == constraint.getRel() && left.equals(constraint.getLeft()) && right.equals(constraint.getRight());
} }
@Override
public int hashCode() {
return (left+right).hashCode();
}
@Override
public boolean equals (Object o) {
if (o instanceof TPHConstraint) {
TPHConstraint o_tphcons = (TPHConstraint)o;
return (this.left.equals(o_tphcons.getLeft())
&& this.right.equals(o_tphcons.getRight())
&& this.rel.equals(o_tphcons.rel));
}
else {
return false;
}
}
@Override @Override
public String toString() { public String toString() {
if(rel == Relation.EXTENDS) { if(rel == Relation.EXTENDS) {

View File

@@ -3,16 +3,14 @@
*/ */
package de.dhbwstuttgart.bytecode.genericsGenerator; package de.dhbwstuttgart.bytecode.genericsGenerator;
import java.util.ArrayList; import java.util.*;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import de.dhbwstuttgart.bytecode.TPHExtractor; import de.dhbwstuttgart.bytecode.TPHExtractor;
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.*;
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResultForClass;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.MethodAndConstraints;
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH; import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
import de.dhbwstuttgart.bytecode.utilities.MethodUtility; import de.dhbwstuttgart.bytecode.utilities.MethodUtility;
import de.dhbwstuttgart.bytecode.utilities.Resolver; import de.dhbwstuttgart.bytecode.utilities.Resolver;
@@ -81,6 +79,7 @@ public class GeneratedGenericsFinder implements ASTVisitor {
private JavaClassName className; private JavaClassName className;
private Resolver resolver; private Resolver resolver;
/** /**
* @param sf * @param sf
* @param listOfResultSets * @param listOfResultSets
@@ -95,6 +94,14 @@ public class GeneratedGenericsFinder implements ASTVisitor {
return generatedGenericsForSF; return generatedGenericsForSF;
} }
/**
* returns the family of Generated Generics
* insbesondere fuer Testzwecke
*/
public FamilyOfGeneratedGenerics getFogg() {
return fogg;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@@ -127,6 +134,7 @@ public class GeneratedGenericsFinder implements ASTVisitor {
ConstraintsSimplierResult simplifiedConstraints = null; ConstraintsSimplierResult simplifiedConstraints = null;
GenericsGeneratorResultForClass ggResult = null; GenericsGeneratorResultForClass ggResult = null;
GenericsGeneratorResultForClass ggResultAlternative = null;
for (int i = 0; i < listOfResultSetsList.size(); i++) { for (int i = 0; i < listOfResultSetsList.size(); i++) {
resultSet = listOfResultSetsList.get(i); resultSet = listOfResultSetsList.get(i);
@@ -135,9 +143,19 @@ public class GeneratedGenericsFinder implements ASTVisitor {
classOrInterface.accept(tphExtractor); classOrInterface.accept(tphExtractor);
//PL 2020-10-16: Ab hier GGenerics implementieren durch Ali //PL 2020-10-16: Ab hier GGenerics implementieren durch Ali
//Rueckgabe an generatedGenericsForSF //Rueckgabe an generatedGenericsForSF
fogg = new FamilyOfGeneratedGenerics(tphExtractor); fogg = new FamilyOfGeneratedGenerics(tphExtractor, resultSet);
System.out.println("fogg.allConstraints: "+ fogg.allConstraints);
System.out.println("fogg.posOfTPHs: "+ fogg.posOfTPHs);
System.out.println("fogg.classConstraints: "+ fogg.classConstraints);
System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition);
System.out.println(fogg);
///*
//Fayez Ansatz Anfang
tphsClass = tphExtractor.tphsClass; tphsClass = tphExtractor.tphsClass;
//PL 2020-01-15
//Es muss ggResult aus fogg gebildet werden
simplifiedConstraints = GenericsGenerator.simplifyConstraints(tphExtractor, tphsClass); simplifiedConstraints = GenericsGenerator.simplifyConstraints(tphExtractor, tphsClass);
if(!isVisited) { if(!isVisited) {
ggResult = GenericsGenerator.generateConstraints(className, tphExtractor, tphsClass,simplifiedConstraints); ggResult = GenericsGenerator.generateConstraints(className, tphExtractor, tphsClass,simplifiedConstraints);
@@ -146,12 +164,45 @@ public class GeneratedGenericsFinder implements ASTVisitor {
for(Method m : classOrInterface.getMethods()) { for(Method m : classOrInterface.getMethods()) {
addMethodConstraints(simplifiedConstraints, ggResult, m); addMethodConstraints(simplifiedConstraints, ggResult, m);
} }
if(ggResult != null)
if(ggResult != null) { //Hinzufuegen von Fayez ggResult
generatedGenericsForSF.addGenericGeneratorResultClass(ggResult); generatedGenericsForSF.addGenericGeneratorResultClass(ggResult);
System.out.println("ddd"); }
// Fayez Ansatz Ende
//*/
//Ali Ansatz Anfang
List<GenericsGeneratorResult> listOfClassCons = new ArrayList<>();
for(TPHConstraint clCons: fogg.classConstraints) {
// ExtendsConstraint ec = new ExtendsConstraint(clCons.getLeft(), clCons.getRight());
GenericsGeneratorResult ggR = new GenericsGeneratorResult(clCons, new HashSet<>());
listOfClassCons.add(ggR);
}
GenericGeneratorResultsForAllMethods ggRfaM = null;
List<MethodAndConstraints> listOfMethAndCons = new ArrayList<>();
for(String methID: fogg.methodConstraintsWithPosition.keySet()) {
List<GenericsGeneratorResult> listOfGGR = new ArrayList<>();
for(TPHConstraint methCons: fogg.methodConstraintsWithPosition.get(methID)) {
// ExtendsConstraint ec = new ExtendsConstraint(methCons.getLeft(),methCons.getRight());
GenericsGeneratorResult ggR = new GenericsGeneratorResult(methCons, new HashSet<>());
listOfGGR.add(ggR);
}
MethodAndConstraints mac = new MethodAndConstraints(methID, listOfGGR);
listOfMethAndCons.add(mac);
}
ggRfaM = new GenericGeneratorResultsForAllMethods(listOfMethAndCons);
ggResultAlternative = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM);
if(ggResultAlternative != null) {//hinzufuegen von Alis ggResult
//generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative);
System.out.println(generatedGenericsForSF);
}
System.out.println(ggResultAlternative);
//Ali Ansatz Ende
} }

View File

@@ -29,5 +29,13 @@ public class GenericGeneratorResultsForAllMethods {
public List<MethodAndConstraints> getMethodsAndConstraints() { public List<MethodAndConstraints> getMethodsAndConstraints() {
return methodsAndConstraints; return methodsAndConstraints;
} }
@Override
public String toString() {
String ret = "";
ret = ret + methodsAndConstraints.stream().reduce("", (x,y) -> x + y.toString(), (x,y) -> x + y);
//ret = ret + "\n";
return ret;
}
} }

View File

@@ -52,4 +52,8 @@ public class GenericsGeneratorResult {
this.equalsTPHs = equalsTPHs; this.equalsTPHs = equalsTPHs;
} }
@Override
public String toString() {
return constraint.toString() + " EqualsTPS: " + equalsTPHs.toString();
}
} }

View File

@@ -73,4 +73,12 @@ public class GenericsGeneratorResultForClass {
return Collections.emptyList(); return Collections.emptyList();
} }
} }
@Override
public String toString() {
String ret = "Classconstraints: ";
ret = ret + classConstraints.stream().reduce("", (x,y) -> x + y.toString(), (x,y) -> x + y);
ret = ret + "\n" + methodsAndTheirConstraints.toString();
return ret;
}
} }

View File

@@ -33,4 +33,14 @@ public class MethodAndConstraints {
return constraints; return constraints;
} }
@Override
public String toString() {
String ret = methodID + ": ";
ret = ret + constraints.stream().reduce("",
(x,y) -> x + y.toString(),
(x,y) -> x + y);
ret = ret + "\n";
return ret;
}
} }

View File

@@ -1,6 +1,7 @@
package de.dhbwstuttgart.bytecode.insertGenerics; package de.dhbwstuttgart.bytecode.insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
public class ClassConstraint extends TPHConstraint { public class ClassConstraint extends TPHConstraint {
//private TPHConstraint constraint; //private TPHConstraint constraint;

View File

@@ -1,31 +1,47 @@
package de.dhbwstuttgart.bytecode.insertGenerics; package de.dhbwstuttgart.bytecode.insertGenerics;
import com.ibm.icu.text.CurrencyMetaInfo;
import de.dhbwstuttgart.bytecode.TPHExtractor; import de.dhbwstuttgart.bytecode.TPHExtractor;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH; import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap; import java.util.function.Predicate;
import java.util.List;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.ResultPair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import org.objectweb.asm.Type;
public class FamilyOfGeneratedGenerics { public class FamilyOfGeneratedGenerics {
public List<TPHConstraint> allConstraints = new ArrayList<>(); public List<TPHConstraint> allConstraints = new ArrayList<>();
// HashMap speichert ob TPH in einer Methode oder in der Klasse ist; und wenn es in der Methode ist, in welcher Methode // HashMap speichert ob TPH in einer Methode oder in der Klasse ist; und wenn es in der Methode ist, in welcher Methode
public HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTPHs = new HashMap<>(); public HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTPHs = new HashMap<>();
public List<ClassConstraint> classConstraints = new ArrayList<>(); public List<ClassConstraint> classConstraints = new ArrayList<>();
private HashMap<String, MethodAndTPH> mapMethodsAndTph = new HashMap<>();
public List<MethodConstraint> methodConstraints = new ArrayList<>(); public List<MethodConstraint> methodConstraints = new ArrayList<>();
public HashMap<String, List<MethodConstraint>> methodConstraintsWithPosition = new HashMap<>();
public ResultSet resSet;
public Set<Pair> oldCons = new HashSet<>();
private static final String objectType = Type.getInternalName(Object.class);
public FamilyOfGeneratedGenerics(TPHExtractor tphExtractor) { public FamilyOfGeneratedGenerics(TPHExtractor tphExtractor, ResultSet resultSet) {
this.resSet = resultSet;
this.oldCons = tphExtractor.oldConstraints;
this.allConstraints = tphExtractor.allCons; this.allConstraints = tphExtractor.allCons;
this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph); this.posOfTPHs = positionConverter(tphExtractor.allTPHS, tphExtractor.ListOfMethodsAndTph);
this.classConstraints = getClassConstraints(allConstraints,posOfTPHs); this.classConstraints = getClassConstraints(allConstraints,posOfTPHs);
// this.methodConstraints = tphExtractor.ListOfMethodsAndTph.forEach(matph -> this.mapMethodsAndTph.put(matph.getId(), matph));
this.methodConstraints = getMethodConstraints(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph);
this.methodConstraintsWithPosition = getMethodConstraintsWithPositionNew(allConstraints,classConstraints,posOfTPHs, tphExtractor.ListOfMethodsAndTph, resSet, oldCons);
} }
public static List<ClassConstraint> getClassConstraints(List<TPHConstraint> cs, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { //Inputparameter List<TPHConstraint> constraintsSet weg public static List<ClassConstraint> getClassConstraints(List<TPHConstraint> cs, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs) { //Inputparameter List<TPHConstraint> constraintsSet weg
List<ClassConstraint> cs_cl = new ArrayList<>(); List<ClassConstraint> cs_cl = new ArrayList<>();
List<ClassConstraint> classConstraints1 = typeOfANodeOfAField(cs, posOfTphs); List<ClassConstraint> classConstraints1 = typeOfANodeOfAField(cs, posOfTphs);
for (ClassConstraint cons: classConstraints1) { for (ClassConstraint cons: classConstraints1) {
@@ -33,13 +49,21 @@ public class FamilyOfGeneratedGenerics {
cs_cl.add(cons); cs_cl.add(cons);
} }
} }
List<ClassConstraint> classConstraints2 = transitiveSubtypeForClassTypes(cs, cs_cl); // in Klammer classConstraints1 oder constraintsSet? beides eher
for (ClassConstraint cons: classConstraints2) { // if sth new is added to cs_cl, then do same step again
if (!checkForDuplicates(cons, cs_cl)) { boolean addedToConstraintsListForCC2 = false;
cs_cl.add(cons); do {
addedToConstraintsListForCC2 = false;
List<ClassConstraint> classConstraints2 = transitiveSubtypeForClassTypes(cs, cs_cl); // in Klammer classConstraints1 oder constraintsSet? beides eher
for (ClassConstraint cons: classConstraints2) {
if (!checkForDuplicates(cons, cs_cl)) {
cs_cl.add(cons);
addedToConstraintsListForCC2 = true;
}
} }
} } while (addedToConstraintsListForCC2);
List<ClassConstraint> classConstraints3 = hasNoSupertypeForClassTypes(cs, cs_cl, posOfTphs);
List<ClassConstraint> classConstraints3 = hasNoSupertypeForClassTypes(cs_cl, posOfTphs);
for (ClassConstraint cons: classConstraints3) { for (ClassConstraint cons: classConstraints3) {
if (!checkForDuplicates(cons, cs_cl)) { if (!checkForDuplicates(cons, cs_cl)) {
cs_cl.add(cons); cs_cl.add(cons);
@@ -48,8 +72,7 @@ public class FamilyOfGeneratedGenerics {
return cs_cl; return cs_cl;
} }
public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { public List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph) {
//TODO: Regeln
List<MethodConstraint> cs_m = new ArrayList<>(); List<MethodConstraint> cs_m = new ArrayList<>();
List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs); List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs);
for (MethodConstraint cons: methodConstraints1) { for (MethodConstraint cons: methodConstraints1) {
@@ -57,19 +80,33 @@ public class FamilyOfGeneratedGenerics {
cs_m.add(cons); cs_m.add(cons);
} }
} }
List<MethodConstraint> methodConstraints2 = firstTransitiveSubtypeForMethodTypes(cs, cs_m);
for (MethodConstraint cons: methodConstraints2) { // if sth new is added to cs_cl, then do same step again
if (!checkForDuplicates(cons, cs_m)) { boolean addedToConstraintsListForMC2 = false;
cs_m.add(cons); do {
addedToConstraintsListForMC2 = false;
List<MethodConstraint> methodConstraints2 = firstTransitiveSubtypeForMethodTypes(cs, cs_m);
for (MethodConstraint cons : methodConstraints2) {
if (!checkForDuplicates(cons, cs_m)) {
cs_m.add(cons);
addedToConstraintsListForMC2 = true;
}
} }
} } while (addedToConstraintsListForMC2);
List<MethodConstraint> methodConstraints3 = secondTransitiveSubtypeForMethodTypes(cs, cs_cl, cs_m);
for (MethodConstraint cons: methodConstraints3) { // if sth new is added to cs_cl, then do same step again
if (!checkForDuplicates(cons, cs_m)) { boolean addedToConstraintsListForMC3 = false;
cs_m.add(cons); do {
addedToConstraintsListForMC3 = false;
List<MethodConstraint> methodConstraints3 = secondTransitiveSubtypeForMethodTypes(cs, cs_cl, cs_m);
for (MethodConstraint cons : methodConstraints3) {
if (!checkForDuplicates(cons, cs_m)) {
cs_m.add(cons);
addedToConstraintsListForMC3 = true;
}
} }
} } while (addedToConstraintsListForMC3);
List<MethodConstraint> methodConstraints4 = hasNoSupertypeForMethodTypes(cs, posOfTphs); List<MethodConstraint> methodConstraints4 = hasNoSupertypeForMethodTypes(cs, cs_m, posOfTphs, listOfMethodsAndTph);
for (MethodConstraint cons: methodConstraints4) { for (MethodConstraint cons: methodConstraints4) {
if (!checkForDuplicates(cons, cs_m)) { if (!checkForDuplicates(cons, cs_m)) {
cs_m.add(cons); cs_m.add(cons);
@@ -80,20 +117,78 @@ public class FamilyOfGeneratedGenerics {
return cs_m; return cs_m;
} }
public HashMap<String, List<MethodConstraint>> getMethodConstraintsWithPosition(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph, ResultSet resSet, Set<Pair> oldCons) {
HashMap<String, List<MethodConstraint>> tempMethodConstraintsWithPosition = new HashMap<>();
for(MethodAndTPH method: listOfMethodsAndTph){
List<String> methodsAddedToHashMap = new ArrayList<>();
String currentMethod = method.getId();
boolean containsCurrentMethod = false;
if(!containsCurrentMethod) {
methodsAddedToHashMap.add(currentMethod);
containsCurrentMethod = true;
List<MethodConstraint> listOfThisMethod = new ArrayList<>();
HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTPHsForThisMethod = new HashMap<>();
for(String s: posOfTphs.keySet()) {
for(PairTphMethod pair: posOfTphs.get(s)) {
if(pair.snd == currentMethod && pair.snd != null) {
posOfTPHsForThisMethod.put(s,posOfTphs.get(s));
}
}
}
listOfThisMethod = getMethodConstraints(cs,cs_cl,posOfTPHsForThisMethod,listOfMethodsAndTph);
tempMethodConstraintsWithPosition.put(currentMethod, listOfThisMethod);
List<MethodConstraint> newMCList = firstLineMethodDefinition(cs, posOfTphs, method, resSet);
List<MethodConstraint> newMCList2 = secondLineMethodDefinition(cs, posOfTphs, method, resSet, oldCons);
System.out.println(newMCList);
System.out.println(newMCList2);
}
}
for(String curMeth: tempMethodConstraintsWithPosition.keySet()){
for(int i=0; i<tempMethodConstraintsWithPosition.get(curMeth).size(); i++) {
MethodConstraint currentMC = tempMethodConstraintsWithPosition.get(curMeth).get(i);
if(currentMC.getRight()!= objectType && !compareTphsOfConstraints(currentMC.getRight(), cs_cl) && !compareTphsOfConstraints(currentMC.getRight(), tempMethodConstraintsWithPosition.get(curMeth))) {
MethodConstraint mc = new MethodConstraint(currentMC.getRight(), objectType, Relation.EXTENDS);
tempMethodConstraintsWithPosition.get(curMeth).add(mc);
}
}
}
return tempMethodConstraintsWithPosition;
}
// Hilfsmethode um TPHs in den Methoden zu finden, die <. Object sein müssen
private static boolean compareTphsOfConstraints(String tph, List list) {
List<TPHConstraint> tempList = new ArrayList<>(list);
for(TPHConstraint tphC: tempList) {
if(tph == tphC.getLeft()) {
return true;
}
}
return false;
}
/** /**
* Def. FGG: erste Zeile von cs_cl * Def. FGG: erste Zeile von cs_cl
* {T < .T' | T is a type variable in a type of a node of a field} * {T < .T' | T is a type variable in a type of a node of a field}
*/ */
public static List<ClassConstraint> typeOfANodeOfAField(List<TPHConstraint> allConstraints, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { public static List<ClassConstraint> typeOfANodeOfAField(List<TPHConstraint> allConstraints, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs) {
//RuntimeException re = new RuntimeException("enthält EQUALS-Relation"); //RuntimeException re = new RuntimeException("enthält EQUALS-Relation");
List<ClassConstraint> tempCC= new ArrayList<>(); List<ClassConstraint> tempCC = new ArrayList<>();
for(TPHConstraint allCons: allConstraints){ for(TPHConstraint allCons: allConstraints){
if(posOfTphs.containsKey(allCons.getLeft()) && allCons.getRight()!=null && allCons.getRel()==Relation.EXTENDS) { if(posOfTphs.containsKey(allCons.getLeft()) && allCons.getRight()!=null && allCons.getRel()==Relation.EXTENDS) {
for(String tph: posOfTphs.keySet()) { for(String tph: posOfTphs.keySet()) {
if(tph == allCons.getLeft() && posOfTphs.get(tph).fst == PositionFinder.Position.FIELD) { for(PairTphMethod pair: posOfTphs.get(tph)) {
ClassConstraint consToAdd = new ClassConstraint(tph, allCons.getRight(), allCons.getRel()); if(tph == allCons.getLeft() && pair.fst == PositionFinder.Position.FIELD) {
if (!checkForDuplicates(consToAdd, tempCC)) { ClassConstraint consToAdd = new ClassConstraint(tph, allCons.getRight(), allCons.getRel());
tempCC.add(consToAdd); if (!checkForDuplicates(consToAdd, tempCC)) {
tempCC.add(consToAdd);
}
/*}else if(pair.fst == PositionFinder.Position.FIELD){
ClassConstraint consToAdd = new ClassConstraint(tph, objectType, Relation.EXTENDS);
if (!checkForDuplicates(consToAdd, tempCC)) {
tempCC.add(consToAdd);
}*/
} }
} }
} }
@@ -110,12 +205,13 @@ public class FamilyOfGeneratedGenerics {
* {T' <. T'' | \exists T: (T <. T') \in cs_cl, (T' <. T'') \in cs } * {T' <. T'' | \exists T: (T <. T') \in cs_cl, (T' <. T'') \in cs }
*/ */
public static List<ClassConstraint> transitiveSubtypeForClassTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl) { public static List<ClassConstraint> transitiveSubtypeForClassTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl) {
List<ClassConstraint> tempCC= new ArrayList<>(); List<ClassConstraint> tempCC = new ArrayList<>();
ClassConstraint consToAdd;
for(ClassConstraint cCons: cs_cl) { for(ClassConstraint cCons: cs_cl) {
if(cCons.getLeft() != null && cCons.getRel()==Relation.EXTENDS) { if(cCons.getLeft() != null && cCons.getRel()==Relation.EXTENDS) {
for(TPHConstraint allCons: allConstraints) { for(TPHConstraint allCons: allConstraints) {
if(cCons.getRight() == allCons.getLeft() && allCons.getRight() != null && allCons.getRel()==Relation.EXTENDS){ if(cCons.getRight() == allCons.getLeft() && allCons.getRight() != null && allCons.getRel()==Relation.EXTENDS){
ClassConstraint consToAdd = new ClassConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel()); consToAdd = new ClassConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel());
if (!checkForDuplicates(consToAdd, tempCC)) { if (!checkForDuplicates(consToAdd, tempCC)) {
tempCC.add(consToAdd); tempCC.add(consToAdd);
} }
@@ -131,40 +227,50 @@ public class FamilyOfGeneratedGenerics {
* {T <. Object | ((T is a type variable in a type of a node of a field * {T <. Object | ((T is a type variable in a type of a node of a field
* or (\exists T~: (T~ <. T) \in cs_cl)) and (\existsnot T': T <. T') \in cs)} * or (\exists T~: (T~ <. T) \in cs_cl)) and (\existsnot T': T <. T') \in cs)}
*/ */
public static List<ClassConstraint> hasNoSupertypeForClassTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { public static List<ClassConstraint> hasNoSupertypeForClassTypes(List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs) {
List<ClassConstraint> tempCC= new ArrayList<>(); List<ClassConstraint> tempCC= new ArrayList<>();
for(TPHConstraint allCons: allConstraints) { List<TPHConstraint> clCons = new ArrayList<>(cs_cl);
for(ClassConstraint cCons: cs_cl) { for(String tph: posOfTphs.keySet()) {
for(String tph: posOfTphs.keySet()) { for(PairTphMethod pair: posOfTphs.get(tph)) {
boolean tvInField = posOfTphs.get(tph).fst == PositionFinder.Position.FIELD; boolean tvInField = pair.fst == PositionFinder.Position.FIELD;
boolean hasSmallerTVInClCons = (posOfTphs.containsKey(cCons.getRight()) && cCons.getRight() == tph && cCons.getLeft() != null); boolean hasSmallerTVInClCons = hasSmallerTVInClCons(tph, cs_cl);
if( ((tvInField || hasSmallerTVInClCons) && cCons.getRel()==Relation.EXTENDS) && if ((tvInField || hasSmallerTVInClCons) &&
checkUpperBound(allConstraints, tph) && allCons.getRel()==Relation.EXTENDS) { !checkUpperBound(clCons, tph)) {
ClassConstraint consToAdd = new ClassConstraint(tph, "Object", Relation.EXTENDS); ClassConstraint consToAdd = new ClassConstraint(tph, objectType, Relation.EXTENDS);
if (!checkForDuplicates(consToAdd, tempCC)){ if (!checkForDuplicates(consToAdd, tempCC)) {
tempCC.add(consToAdd); tempCC.add(consToAdd);
} }
} }
} }
} }
}
return tempCC; return tempCC;
} }
public static boolean hasSmallerTVInClCons(String tph, List<ClassConstraint> cs_cl) {
for(ClassConstraint cC: cs_cl) {
if(tph == cC.getRight() && cC.getRel() == Relation.EXTENDS) {
return true;
}
}
return false;
}
/** /**
* Def. FGG: erste Zeile von cs_m * Def. FGG: erste Zeile von cs_m
* {T < .T' | T is a type variable in a type of the method/constructor m in cl_\sigma, (T <. T') \in cs} * {T < .T' | T is a type variable in a type of the method/constructor m in cl_\sigma, (T <. T') \in cs}
*/ */
public static List<MethodConstraint> typeOfTheMethodInClSigma(List<TPHConstraint> allConstraints, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { // cl_\sigma?? public static List<MethodConstraint> typeOfTheMethodInClSigma(List<TPHConstraint> allConstraints, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs) { // cl_\sigma??
//TODO: //TODO:
List<MethodConstraint> tempMC= new ArrayList<>(); List<MethodConstraint> tempMC= new ArrayList<>();
for(TPHConstraint allCons: allConstraints){ for(TPHConstraint allCons: allConstraints){
if(posOfTphs.containsKey(allCons.getLeft()) && allCons.getRight()!=null && allCons.getRel()==Relation.EXTENDS) { if(posOfTphs.containsKey(allCons.getLeft()) && allCons.getRight()!=null && allCons.getRel()==Relation.EXTENDS) {
for(String tph: posOfTphs.keySet()) { for(String tph: posOfTphs.keySet()) {
if(tph == allCons.getLeft() && (posOfTphs.get(tph).fst == PositionFinder.Position.METHOD || posOfTphs.get(tph).fst == PositionFinder.Position.CONSTRUCTOR)) { for(PairTphMethod pair: posOfTphs.get(tph)) {
MethodConstraint consToAdd = new MethodConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel()); if(tph == allCons.getLeft() && (pair.fst == PositionFinder.Position.METHOD || pair.fst == PositionFinder.Position.CONSTRUCTOR)) {
if (!checkForDuplicates(consToAdd, tempMC)) { MethodConstraint consToAdd = new MethodConstraint(allCons.getLeft(), allCons.getRight(), allCons.getRel());
tempMC.add(consToAdd); if (!checkForDuplicates(consToAdd, tempMC)) {
tempMC.add(consToAdd);
}
} }
} }
} }
@@ -178,7 +284,7 @@ public class FamilyOfGeneratedGenerics {
* Def. FGG: zweite Zeile von cs_m * Def. FGG: zweite Zeile von cs_m
* {R' <. S | (R <. R'), (S <. S') \in cs_m and (R',S) is in the transitive closure of cs} * {R' <. S | (R <. R'), (S <. S') \in cs_m and (R',S) is in the transitive closure of cs}
*/ */
public static List<MethodConstraint> firstTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m) { //transitive closure of cs public List<MethodConstraint> firstTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m) { //transitive closure of cs
//TODO: //TODO:
List<MethodConstraint> tempMC= new ArrayList<>(); List<MethodConstraint> tempMC= new ArrayList<>();
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints); List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
@@ -203,7 +309,7 @@ public class FamilyOfGeneratedGenerics {
* Def. FGG: dritte Zeile von cs_m * Def. FGG: dritte Zeile von cs_m
* {R' <. S | (R <. R') \in cs_m, (S <. S') \in cs_cl and (R',S) is in the transitive closure of cs} * {R' <. S | (R <. R') \in cs_m, (S <. S') \in cs_cl and (R',S) is in the transitive closure of cs}
*/ */
public static List<MethodConstraint> secondTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) { public List<MethodConstraint> secondTransitiveSubtypeForMethodTypes(List<TPHConstraint> allConstraints, List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) {
//TODO: //TODO:
List<MethodConstraint> tempMC= new ArrayList<>(); List<MethodConstraint> tempMC= new ArrayList<>();
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints); List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
@@ -216,7 +322,6 @@ public class FamilyOfGeneratedGenerics {
MethodConstraint consToAdd = new MethodConstraint(tphC.getLeft(), tphC.getRight(), tphC.getRel()); MethodConstraint consToAdd = new MethodConstraint(tphC.getLeft(), tphC.getRight(), tphC.getRel());
if (!checkForDuplicates(consToAdd, tempMC)) { if (!checkForDuplicates(consToAdd, tempMC)) {
tempMC.add(consToAdd); tempMC.add(consToAdd);
System.out.println(consToAdd);
} }
} }
@@ -231,16 +336,32 @@ public class FamilyOfGeneratedGenerics {
* {T <. Object | (T is a type variable in a type of a node of the method/constructor m in cl_\sigma), * {T <. Object | (T is a type variable in a type of a node of the method/constructor m in cl_\sigma),
* (\existsnot T': T <. T') \in cs)} * (\existsnot T': T <. T') \in cs)}
*/ */
public static List<MethodConstraint> hasNoSupertypeForMethodTypes(List<TPHConstraint> allConstraints, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) { public static List<MethodConstraint> hasNoSupertypeForMethodTypes(List<TPHConstraint> allConstraints, List<MethodConstraint> cs_m, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph) {
//TODO: //TODO:
List<MethodConstraint> tempMC= new ArrayList<>(); List<MethodConstraint> tempMC= new ArrayList<>();
for(String tph: posOfTphs.keySet()) { for(String tph: posOfTphs.keySet()) {
for(TPHConstraint allCons: allConstraints) { for(PairTphMethod pair: posOfTphs.get(tph)) {
if((posOfTphs.get(tph).fst.equals(PositionFinder.Position.METHOD) || posOfTphs.get(tph).fst.equals(PositionFinder.Position.CONSTRUCTOR)) && checkUpperBound(allConstraints,tph)) { for(TPHConstraint allCons: allConstraints) {
MethodConstraint consToAdd = new MethodConstraint(tph, "Object", Relation.EXTENDS); if((pair.fst.equals(PositionFinder.Position.METHOD) || pair.fst.equals(PositionFinder.Position.CONSTRUCTOR)) && !checkUpperBound(allConstraints,tph)) {
if (!checkForDuplicates(consToAdd, tempMC)) { MethodConstraint consToAdd = new MethodConstraint(tph, objectType, Relation.EXTENDS);
tempMC.add(consToAdd); if (!checkForDuplicates(consToAdd, tempMC)) {
System.out.println(consToAdd); tempMC.add(consToAdd);
}
}
}
List<TPHConstraint> tempMCObject1 = new ArrayList<>(cs_m);
String currentMethod = "";
for(MethodAndTPH mat: listOfMethodsAndTph) {
if(mat.getId().equals(pair.snd)) {
currentMethod = mat.getId();
}
for(TPHConstraint mc1: tempMCObject1) {
if(tph==mc1.getRight() && !checkUpperBound(tempMCObject1,tph)) {
MethodConstraint consToAdd = new MethodConstraint(tph, objectType, Relation.EXTENDS);
if (!checkForDuplicates(consToAdd, tempMC)) {
tempMC.add(consToAdd);
}
}
} }
} }
} }
@@ -251,13 +372,16 @@ public class FamilyOfGeneratedGenerics {
/** /**
* nimm die Menge cs_cl aus cs_m raus * nimm die Menge cs_cl aus cs_m raus
*/ */
public static List<MethodConstraint> methodTypesWithoutClassTypes(List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) { public List<MethodConstraint> methodTypesWithoutClassTypes(List<ClassConstraint> cs_cl, List<MethodConstraint> cs_m) {
//TODO: // erstelle Kopie der Liste cs_cl
List<TPHConstraint> tempCC = new ArrayList<>(); List<TPHConstraint> tempCC = new ArrayList<>();
for(ClassConstraint cc: cs_cl) { for(ClassConstraint cc: cs_cl) {
TPHConstraint tphC = new TPHConstraint(cc.getLeft(), cc.getRight(), cc.getRel()); TPHConstraint tphC = new TPHConstraint(cc.getLeft(), cc.getRight(), cc.getRel());
tempCC.add(tphC); tempCC.add(tphC);
} }
// Transitive Hülle von cs_cl
List<TPHConstraint> tcOfCsCl = buildTransitiveClosure(tempCC);
List<TPHConstraint> tempMC = new ArrayList<>(); List<TPHConstraint> tempMC = new ArrayList<>();
for(MethodConstraint mc: cs_m) { for(MethodConstraint mc: cs_m) {
TPHConstraint tphC = new TPHConstraint(mc.getLeft(), mc.getRight(), mc.getRel()); TPHConstraint tphC = new TPHConstraint(mc.getLeft(), mc.getRight(), mc.getRel());
@@ -267,7 +391,7 @@ public class FamilyOfGeneratedGenerics {
tempMC2.addAll(tempMC); tempMC2.addAll(tempMC);
List<MethodConstraint> tempMCToReturn = new ArrayList<>(); List<MethodConstraint> tempMCToReturn = new ArrayList<>();
for(TPHConstraint cc: tempCC) { for(TPHConstraint cc: tcOfCsCl) {
for(TPHConstraint mc: tempMC) { for(TPHConstraint mc: tempMC) {
if(cc.getLeft().equals(mc.getLeft()) && cc.getRight().equals(mc.getRight())) { if(cc.getLeft().equals(mc.getLeft()) && cc.getRight().equals(mc.getRight())) {
tempMC2.remove(mc); tempMC2.remove(mc);
@@ -294,7 +418,7 @@ public class FamilyOfGeneratedGenerics {
return false; return false;
} }
public static List<TPHConstraint> buildTransitiveClosure(List list) { public List<TPHConstraint> buildTransitiveClosure(List list) {
List<TPHConstraint> iterList = new ArrayList<>(list); List<TPHConstraint> iterList = new ArrayList<>(list);
List<TPHConstraint> runList = new ArrayList<>(list); List<TPHConstraint> runList = new ArrayList<>(list);
List<TPHConstraint> tcList = new ArrayList<>(list); List<TPHConstraint> tcList = new ArrayList<>(list);
@@ -319,25 +443,28 @@ public class FamilyOfGeneratedGenerics {
public static boolean checkUpperBound(List<TPHConstraint> cs, String tph) { public static boolean checkUpperBound(List<TPHConstraint> cs, String tph) {
for(int i=0; i<cs.size(); i++) { for(int i=0; i<cs.size(); i++) {
if(cs.get(i).getLeft() == tph) { if(cs.get(i).getLeft() == tph) {
return false; //has upper bound
return true;
} }
} }
return true; return false;
} }
public static HashMap<String, PairTphMethod<PositionFinder.Position, String>> positionConverter(HashMap<String, Boolean> allTphs, List<MethodAndTPH> listOfMethodsAndTphs) { public static HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> positionConverter(HashMap<String, Boolean> allTphs, List<MethodAndTPH> listOfMethodsAndTphs) {
HashMap<String, PairTphMethod<PositionFinder.Position, String>> convertedPositions = new HashMap<>(); HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> convertedPositions = new HashMap<>();
for(String tph: allTphs.keySet()) { for(String tph: allTphs.keySet()) {
List<PairTphMethod<PositionFinder.Position, String>> currMeth = new ArrayList<>();
if(allTphs.get(tph)) { //if true, then tph is a method-TPH if(allTphs.get(tph)) { //if true, then tph is a method-TPH
for(MethodAndTPH methTph: listOfMethodsAndTphs) { for(MethodAndTPH methTph: listOfMethodsAndTphs) {
if (methTph.getTphs().contains(tph)) { if (methTph.getTphs().contains(tph)) {
convertedPositions.put(tph, new PairTphMethod<>(PositionFinder.Position.METHOD, methTph.getId())); currMeth.add(new PairTphMethod<>(PositionFinder.Position.METHOD, methTph.getId()));
} }
} }
} else { // else it is in the class-TPH } else { // else it is in the class-TPH
convertedPositions.put(tph, new PairTphMethod<>(PositionFinder.Position.FIELD, null)); currMeth.add(new PairTphMethod<>(PositionFinder.Position.FIELD, null));
} }
convertedPositions.put(tph, currMeth);
} }
return convertedPositions; return convertedPositions;
} }
@@ -361,4 +488,393 @@ public class FamilyOfGeneratedGenerics {
} }
*/ */
public static List<MethodConstraint> firstLineMethodDefinition(List<TPHConstraint> allConstraints, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet) {
List<MethodConstraint> tempMC= new ArrayList<>();
MethodAndTPH methAndTphs = methodAndTPH;
Set<Pair> undCons = methAndTphs.constraints.getUndConstraints();
List<Set<Constraint<Pair>>> orCons = methAndTphs.constraints.getOderConstraints();
Iterator<Pair> it = undCons.iterator();
while(it.hasNext()) {
Pair p = it.next();
String ta1 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName();
String ta2 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName();
Relation r = null;
if(p.GetOperator() == PairOperator.SMALLERDOT) {
r = Relation.EXTENDS;
} else if(p.GetOperator() == PairOperator.EQUALSDOT) {
r = Relation.EQUAL;
}
MethodConstraint mc = new MethodConstraint(ta1, ta2, r);
if(mc.getRel() == Relation.EXTENDS) {
if (!mc.getLeft().equals(mc.getRight())) { //eliminieren der Fälle wie AA<.AA
if(!checkForDuplicates(mc, tempMC)) {
tempMC.add(mc);
}
}
}
}
return tempMC;
}
public List<MethodConstraint> secondLineMethodDefinition(List<TPHConstraint> allConstraints, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, MethodAndTPH methodAndTPH, ResultSet resSet, Set<Pair> oldCons) {
List<MethodConstraint> tempMC = new ArrayList<>(); //für Ergebnisse basierend auf der neuen Datenstruktur (Ali)
Set<Pair> tempSet = new HashSet<>(); //für Ergebnisse des ersten Teils der Bedinung basierend auf der alten Datenstruktur
Set<Pair> tempSet2 = new HashSet<>(); //für Ergebnisse des zweiten Teils der Bedingung basierend auf der alten Datenstruktur
Set<Pair> tcOfoldConsSet = buildTransitiveClosureForCP(oldCons, resSet);
List<TPHConstraint> tcOfCs = buildTransitiveClosure(allConstraints);
MethodAndTPH methAndTphs = methodAndTPH;
Set<Pair> undCons = methAndTphs.constraints.getUndConstraints();
List<Set<Constraint<Pair>>> orCons = methAndTphs.constraints.getOderConstraints();
List<HashMap<Relation, List<TPHConstraint>>> orConsListConverted = new ArrayList<>();
//gehe die OrConstraints der aktuellen Methode durch und teile nach Operator auf (
for(int i=0; i<orCons.size(); i++) {
List<TPHConstraint> orConsWithEQUAL = new ArrayList();
List<TPHConstraint> orConsWithEXTENDS = new ArrayList();
HashMap<Relation, List<TPHConstraint>> orConsInternal = new HashMap<>();
for(Constraint con: orCons.get(i)) {
Iterator<Pair> it = con.iterator();
while(it.hasNext()) {
Pair p = it.next();
Relation r = null;
if(p.GetOperator() == PairOperator.SMALLERDOT) {
r = Relation.EXTENDS;
orConsWithEXTENDS.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r));
/*MethodConstraint mc = new MethodConstraint(((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName(), ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName(), r);
if(!checkForDuplicates(mc, tempMC)) {
tempMC.add(mc);
}*/
} else if(p.GetOperator() == PairOperator.EQUALSDOT) {
r = Relation.EQUAL;
orConsWithEQUAL.add(new TPHConstraint(((TypePlaceholder) p.TA1).getName(), ((TypePlaceholder) p.TA2).getName(), r));
/*MethodConstraint mc = new MethodConstraint(((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName(), ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName(), r);
if(!checkForDuplicates(mc, tempMC)) {
tempMC.add(mc);
}*/
}
}
}
orConsInternal.put(Relation.EXTENDS, orConsWithEXTENDS);
orConsInternal.put(Relation.EQUAL, orConsWithEQUAL);
orConsListConverted.add(orConsInternal);
}
// oldCons sind alle Und- und Oder-Constraints
// zunächst in meine Datenstruktur(Ali) konvertieren
List<Pair> oldConsList = new ArrayList<>(oldCons);
List<TPHConstraint> oldConsListConverted = new ArrayList<>();
for(Pair pair: oldConsList) {
Relation r = null;
if(pair.GetOperator() == PairOperator.SMALLERDOT) {
r = Relation.EXTENDS;
} else if(pair.GetOperator() == PairOperator.EQUALSDOT) {
r = Relation.EQUAL;
}
oldConsListConverted.add(new TPHConstraint(((TypePlaceholder) pair.TA1).getName(), ((TypePlaceholder) pair.TA2).getName(), r));
}
// Berechnung des zweiten Teils der Bedingung der Regel
for(int i=0; i<orCons.size(); i++) {
Constraint<Pair> extendsSet = new Constraint<Pair>();
Constraint<Pair> equalSet = new Constraint<Pair>();
//für jede einzelne OrConstraint-Menge gehe durch
for (Constraint con : orCons.get(i)) {
Iterator<Pair> it = con.iterator();
while (it.hasNext()) {
Pair p = it.next();
if (p.OperatorSmallerDot()) {
extendsSet.add(p);
} else if (p.OperatorEqual()) {
equalSet.add(p);
}
}
Iterator<Pair> itExtends2 = extendsSet.iterator();
while(itExtends2.hasNext()) {
Pair pairExtends2 = itExtends2.next();
Set<String> containedVars = new HashSet<>(methodAndTPH.getTphs());
String pairExtends2RHSName = ((TypePlaceholder)((resSet.resolveType((TypePlaceholder)pairExtends2.TA2)).resolvedType)).getName();
Iterator<Pair> itEqual2 = equalSet.iterator();
while (itEqual2.hasNext()) {
boolean transClo = false;
Pair pairEqual2 = itEqual2.next();
//TODO: Auf trans.FamilyOfGeneratedGenerics Huelle pruefen
Pair newPairOld = new Pair(pairExtends2.TA2, pairEqual2.TA1);
Pair newPair2 = new Pair(resSet.resolveType((TypePlaceholder) (pairExtends2.TA2)).resolvedType, resSet.resolveType((TypePlaceholder) (pairEqual2.TA1)).resolvedType, PairOperator.SMALLERDOT);
TPHConstraint newPairTPHConstraint = new TPHConstraint(newPair2);
if (tcOfCs.contains(newPairTPHConstraint)|| (newPairTPHConstraint.getLeft().equals(newPairTPHConstraint.getRight()))) {
transClo = true;
}
TypePlaceholder tphR = (TypePlaceholder) pairEqual2.TA2;
Iterator<Pair> itUndCons = undCons.iterator();
boolean rEqExRtilde = false;
while (itUndCons.hasNext()) {
Pair pairUndCons2 = itUndCons.next();
rEqExRtilde = rEqExRtilde || (tphR == pairUndCons2.TA1);
}
boolean isPairInTExTapostrophe = false;
for(Set<Constraint<Pair>> scp: orCons) {
Iterator<Constraint<Pair>> itSCP = scp.iterator();
while(itSCP.hasNext()) {
Constraint<Pair> cp = itSCP.next();
Iterator<Pair> itCP = cp.iterator();
while(itCP.hasNext()) {
Pair p = itCP.next();
if(p.OperatorSmallerDot()) {
isPairInTExTapostrophe = isPairInTExTapostrophe || tphR.equals(p.TA1);
}
}
}
}
if (transClo && (rEqExRtilde || isPairInTExTapostrophe)) {
if (!newPair2.TA1.equals(newPair2.TA2)) { //eliminieren der Fälle wie AA<.AA
if (!checkForDuplicatesForSets(newPair2, tempSet2)) {
tempSet2.add(newPair2);
}
}
if (!checkForDuplicatesForSets(pairExtends2, tempSet2)) {
tempSet2.add(pairExtends2);
}
}
else {
//containedVars.remove(((TypePlaceholder)newPair2.TA2).getName());
}
}
//String key = ((TypePlaceholder)((resSet.resolveType((TypePlaceholder)pairExtends2.TA2)).resolvedType)).getName();
//TODO: containedVars stimmt noch nicht. Ueberpruefen, ob ggf. mit den containedVars möglicherweise auch die anderen Faelle
// rEqExRtilde isPairInTExTapostrophe abgedeckt sind => ggf. integrieren
/*
posOfTphs.forEach((x,y) -> {
if (y.contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) {
containedVars.add(x);
};
}
);
*/
//Referenzbeispiel Put.jav
if (containedVars.stream().filter(v -> tcOfCs.contains(new TPHConstraint(pairExtends2RHSName, v, Relation.EXTENDS)))
.count() > 0) {
System.out.println();
//tempSet2.add(pairExtends2);
}
if (posOfTphs.containsKey(pairExtends2RHSName)) {//Refrenzbeispiel TestVector.jav
if (posOfTphs.get(pairExtends2RHSName).contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) {
tempSet2.add(pairExtends2);
}
}
}
}
}
// aus der alten Datenstruktur in die neue Datenstruktur (von Ali) für ersten Teil
Iterator<Pair> itTemp = tempSet.iterator();
while(itTemp.hasNext()) {
Pair p = itTemp.next();
String ta1 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName();
String ta2 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName();
Relation r = null;
if(p.GetOperator() == PairOperator.SMALLERDOT) {
r = Relation.EXTENDS;
} else if(p.GetOperator() == PairOperator.EQUALSDOT) {
r = Relation.EQUAL;
}
MethodConstraint mc = new MethodConstraint(ta1, ta2, r);
if(mc.getRel() == Relation.EXTENDS) {
if(!checkForDuplicates(mc, tempMC)) {
tempMC.add(mc);
}
}
}
// aus der alten Datenstruktur in die neue Datenstruktur (von Ali) für zweiten Teil
Iterator<Pair> itTemp2 = tempSet2.iterator();
while(itTemp2.hasNext()) {
Pair p = itTemp2.next();
String ta1 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA1)).resolvedType)).getName();
String ta2 = ((TypePlaceholder) (resSet.resolveType(((TypePlaceholder) p.TA2)).resolvedType)).getName();
Relation r = null;
if (p.GetOperator() == PairOperator.SMALLERDOT) {
r = Relation.EXTENDS;
} else if (p.GetOperator() == PairOperator.EQUALSDOT) {
r = Relation.EQUAL;
}
for(TPHConstraint tphCons: tcOfCs) {//TODO: hier werden Elemente der Trans. clo herausgenommen, aber die dazugehoerigen OrCons nicht.
if(ta1 == tphCons.getLeft() && ta2 == tphCons.getRight() && r==Relation.EXTENDS) {
MethodConstraint mc = new MethodConstraint(ta1, ta2, r);
if(!checkForDuplicates(mc, tempMC)) {
tempMC.add(mc);
}
}
}
}
return tempMC;
}
public static Set<Pair> buildTransitiveClosureForCP(Set constraint, ResultSet resSet) {
Set<Pair> iterSet = new HashSet<>(constraint);
Set<Pair> runSet = new HashSet<>(constraint);
Set<Pair> tcSet = new HashSet<>(constraint);
boolean addedConToList = false;
// for (TPHConstraint cons: iterList) {
Iterator<Pair> itIterSet = iterSet.iterator();
while(itIterSet.hasNext()) {
Pair pairIterSet = itIterSet.next();
// for (TPHConstraint cons2: runList) {
Iterator<Pair> itRunSet = runSet.iterator();
while (itRunSet.hasNext()) {
Pair pairRunSet = itRunSet.next();
// if(cons.getRight() == cons2.getLeft()) {
if(pairIterSet.TA2 == pairRunSet.TA1 && pairIterSet.OperatorSmallerDot() && pairRunSet.OperatorSmallerDot()) {
// TPHConstraint consToAdd = new TPHConstraint(cons.getLeft(), cons2.getRight(), Relation.EXTENDS);
Pair p = new Pair(resSet.resolveType((TypePlaceholder)(pairIterSet.TA1)).resolvedType, resSet.resolveType((TypePlaceholder)(pairRunSet.TA2)).resolvedType, PairOperator.SMALLERDOT);
// if (!checkForDuplicates(consToAdd,tcList)) {
if(!checkForDuplicatesForSets(p, tcSet)) {
// tcList.add(consToAdd);
tcSet.add(p);
addedConToList = true;
if (addedConToList) {
return buildTransitiveClosureForCP(tcSet, resSet);
}
}
}
}
}
System.out.println("tcSet: " + tcSet);
return tcSet;
}
public static boolean checkForDuplicatesForSets(Pair pair, Set set) {
Set<Pair> tempSet = set;
boolean hasSame = false;
// for (TPHConstraint tphC: tempList) {
Iterator<Pair> it = tempSet.iterator();
while (it.hasNext()) {
Pair p = it.next();
// hasSame = constraint.getLeft() == tphC.getLeft() &&
// constraint.getRight() == tphC.getRight() &&
// constraint.getRel() == tphC.getRel(); //constraint already in ArrayList if true
hasSame = pair.TA1 == p.TA1 &&
pair.TA2 == p.TA2 &&
pair.OperatorSmallerDot() && p.OperatorSmallerDot(); //constraint already in Set if true
if (hasSame)
return true;
}
return false;
}
public static List<MethodConstraint> hasNoSupertypeForMethodTypesNew(HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, MethodAndTPH methodAndTPH, List<MethodConstraint> cs_m) {
List<MethodConstraint> tempMC = new ArrayList<>();
List<TPHConstraint> methCons = new ArrayList<>(cs_m);
MethodAndTPH methAndTphs = methodAndTPH;
for(String tph: posOfTphs.keySet()) {
for(int i=0; i<posOfTphs.get(tph).size(); i++)
if(posOfTphs.get(tph).get(i).fst == PositionFinder.Position.METHOD && posOfTphs.get(tph).get(i).snd == methAndTphs.getId() && !checkUpperBound(methCons,tph)) {
MethodConstraint mc2 = new MethodConstraint(tph, objectType, Relation.EXTENDS);
if (!checkForDuplicates(mc2, tempMC)) {
tempMC.add(mc2);
}
}
}
return tempMC;
}
public static List<MethodConstraint> methodTypesWithoutClassTypesNEW(List<String> tphsToCompute, List<MethodConstraint> cs_m) {
List<MethodConstraint> tempMC = new ArrayList<>(cs_m);
List<MethodConstraint> tempMC2 = new ArrayList<>(cs_m);
List<String> toRemove = new ArrayList<>();
for(String tph: tphsToCompute) {
for(TPHConstraint tphCons: tempMC) {
if(tphCons.getLeft() == tph) {
toRemove.add(tphCons.getRight());
tempMC2.remove(tphCons);
tempMC2 = methodTypesWithoutClassTypesNEW(toRemove,tempMC2);
}
}
}
return tempMC2;
}
public HashMap<String, List<MethodConstraint>> getMethodConstraintsWithPositionNew(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph, ResultSet resSet, Set<Pair> oldCons) {
HashMap<String, List<MethodConstraint>> tempMethodConstraintsWithPosition = new HashMap<>();
List<MethodConstraint> newMCList = new ArrayList<>();
List<MethodConstraint> newMCList2 = new ArrayList<>();
List<MethodConstraint> hasNoSupType = new ArrayList<>();
List<MethodConstraint> mcWithoutCc = new ArrayList<>();
List<String> methodsAddedToHashMap = new ArrayList<>();
for(MethodAndTPH method: listOfMethodsAndTph){
String currentMethod = method.getId();
boolean containsCurrentMethod = false;
if(!containsCurrentMethod) {
methodsAddedToHashMap.add(currentMethod);
containsCurrentMethod = true;
List<MethodConstraint> listToAdd = new ArrayList<>();
HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTPHsForThisMethod = new HashMap<>();
for(String s: posOfTphs.keySet()) {
for(PairTphMethod pair: posOfTphs.get(s)) {
if(pair.snd == currentMethod && pair.snd != null) {
posOfTPHsForThisMethod.put(s,posOfTphs.get(s));
}
}
}
newMCList = firstLineMethodDefinition(cs, posOfTphs, method, resSet);
for(int i=0; i<newMCList.size(); i++) {
listToAdd.add(newMCList.get(i));
}
newMCList2 = secondLineMethodDefinition(cs, posOfTphs, method, resSet, oldCons);
for(int i=0; i<newMCList2.size(); i++) {
listToAdd.add(newMCList2.get(i));
}
/*if(!methodsAddedToHashMap.contains(currentMethod)) {
tempMethodConstraintsWithPosition.put(currentMethod, newMCList);
tempMethodConstraintsWithPosition.put(currentMethod, newMCList2);
}*/
hasNoSupType = hasNoSupertypeForMethodTypesNew(posOfTphs,method,listToAdd);
for (MethodConstraint cons: hasNoSupType) {
if (!checkForDuplicates(cons, listToAdd)) {
listToAdd.add(cons);
}
}
mcWithoutCc = listToAdd;
List<String> tphs = new ArrayList<>();
for(String tph: posOfTphs.keySet()) {
for (PairTphMethod p : posOfTphs.get(tph)) {
if(p.fst == PositionFinder.Position.FIELD) {
tphs.add(tph);
mcWithoutCc = methodTypesWithoutClassTypesNEW(tphs, listToAdd);
}
}
}
tempMethodConstraintsWithPosition.put(currentMethod, mcWithoutCc);
}
for(String curMeth: tempMethodConstraintsWithPosition.keySet()){
for(int i=0; i<tempMethodConstraintsWithPosition.get(curMeth).size(); i++) {
MethodConstraint currentMC = tempMethodConstraintsWithPosition.get(curMeth).get(i);
if(currentMC.getRight()!= objectType && !compareTphsOfConstraints(currentMC.getRight(), cs_cl) && !compareTphsOfConstraints(currentMC.getRight(), tempMethodConstraintsWithPosition.get(curMeth))) {
MethodConstraint mc = new MethodConstraint(currentMC.getRight(), objectType, Relation.EXTENDS);
tempMethodConstraintsWithPosition.get(curMeth).add(mc);
}
}
}
}
return tempMethodConstraintsWithPosition;
}
} }

View File

@@ -1,6 +1,7 @@
package de.dhbwstuttgart.bytecode.insertGenerics; package de.dhbwstuttgart.bytecode.insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
public class MethodConstraint extends TPHConstraint { public class MethodConstraint extends TPHConstraint {
public MethodConstraint(String left, String right, Relation rel) { public MethodConstraint(String left, String right, Relation rel) {

View File

@@ -0,0 +1,47 @@
package de.dhbwstuttgart.bytecode.insertGenerics;
import java.util.Objects;
/** A generic class for pairs.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*/
public class PairMethodAndConstraint<A, B> {
public final A fst;
public final B snd;
public PairMethodAndConstraint(A fst, B snd) {
this.fst = fst;
this.snd = snd;
}
public String toString() {
return "PairTphMethod[" + fst + "," + snd + "]";
}
public boolean equals(Object other) {
return
other instanceof PairMethodAndConstraint<?,?> &&
Objects.equals(fst, ((PairMethodAndConstraint<?,?>)other).fst) &&
Objects.equals(snd, ((PairMethodAndConstraint<?,?>)other).snd);
}
public int hashCode() {
if (fst == null) return (snd == null) ? 0 : snd.hashCode() + 1;
else if (snd == null) return fst.hashCode() + 2;
else return fst.hashCode() * 17 + snd.hashCode();
}
public static <A,B> PairMethodAndConstraint<A,B> of(A a, B b) {
return new PairMethodAndConstraint<>(a,b);
}
public PairMethodAndConstraint add(A fst, B snd){
return new PairMethodAndConstraint<>(fst,snd);
}
}

View File

@@ -4,6 +4,8 @@ import java.util.ArrayList;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.GenericInsertPair; import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
import de.dhbwstuttgart.typeinference.result.ResultPair; import de.dhbwstuttgart.typeinference.result.ResultPair;
@@ -15,11 +17,21 @@ public class MethodAndTPH {
private final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> pairs = new ArrayList<>(); private final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> pairs = new ArrayList<>();
// tphs of local variables and parameters // tphs of local variables and parameters
private final ArrayList<String> localTphs = new ArrayList<>(); private final ArrayList<String> localTphs = new ArrayList<>();
/*
* its Constraints
* eingefuegt PL 2021-02-15
*/
public final ConstraintSet constraints;
public MethodAndTPH(String name) { public MethodAndTPH(String name, ConstraintSet<Pair> constraints) {
this.id = name; this.id = name;
this.constraints = constraints;
} }
public void addTph(String tph) {
tphs.add(tph);
}
public ArrayList<String> getTphs() { public ArrayList<String> getTphs() {
return tphs; return tphs;
} }
@@ -39,4 +51,9 @@ public class MethodAndTPH {
return localTphs; return localTphs;
} }
@Override
public String toString() {
return id;
}
} }

View File

@@ -6,6 +6,7 @@ import de.dhbwstuttgart.bytecode.BytecodeGen;
import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError; import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder; import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.environment.CompilationEnvironment; import de.dhbwstuttgart.environment.CompilationEnvironment;
import de.dhbwstuttgart.environment.DirectoryClassLoader; import de.dhbwstuttgart.environment.DirectoryClassLoader;
import de.dhbwstuttgart.exceptions.DebugException; import de.dhbwstuttgart.exceptions.DebugException;
@@ -78,7 +79,12 @@ public class JavaTXCompiler {
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll? Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll?
public volatile UnifyTaskModel usedTasks = new UnifyTaskModel(); public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
private final ClassLoader classLoader; private final ClassLoader classLoader;
//nur fuer Testzwecke of Generated Generics
//wieder loeschen PL 2021-03-22
public FamilyOfGeneratedGenerics fogg;
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException { public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
this(Arrays.asList(sourceFile), null); this(Arrays.asList(sourceFile), null);
} }
@@ -86,6 +92,9 @@ public class JavaTXCompiler {
this(sourceFile); this(sourceFile);
this.log = log; this.log = log;
} }
public JavaTXCompiler(File[] sourceFiles) throws IOException, ClassNotFoundException {
this(Arrays.asList(sourceFiles), null);
}
public JavaTXCompiler(List<File> sourceFiles) throws IOException, ClassNotFoundException { public JavaTXCompiler(List<File> sourceFiles) throws IOException, ClassNotFoundException {
this(sourceFiles, null); this(sourceFiles, null);
} }
@@ -102,7 +111,8 @@ public class JavaTXCompiler {
//INSTANCE = this; //INSTANCE = this;
} }
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException, IOException {
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException, IOException {
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
List<ClassOrInterface> importedClasses = new ArrayList<>(); List<ClassOrInterface> importedClasses = new ArrayList<>();
ClassOrInterface objectClass = ASTFactory.createClass( ClassOrInterface objectClass = ASTFactory.createClass(
@@ -872,6 +882,7 @@ public class JavaTXCompiler {
SourceFile sf = sourceFiles.get(f); SourceFile sf = sourceFiles.get(f);
GeneratedGenericsFinder sResFinder = new GeneratedGenericsFinder(sf, typeinferenceResult); GeneratedGenericsFinder sResFinder = new GeneratedGenericsFinder(sf, typeinferenceResult);
GenericGenratorResultForSourceFile simplifyResOfSF = sResFinder.findGeneratedGenerics(); GenericGenratorResultForSourceFile simplifyResOfSF = sResFinder.findGeneratedGenerics();
this.fogg = sResFinder.getFogg();
result.add(simplifyResOfSF); result.add(simplifyResOfSF);
} }
return result; return result;

View File

@@ -0,0 +1,132 @@
package de.dhbwstuttgart.inferWildcards;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
/**
* Utilities to generate the constraints for the infer wildcards algorithm.
*
* @author Till Schnell
* @version 1.0
*/
public final class ConstraintsGenerationUtils
{
private ConstraintsGenerationUtils () {
throw new AssertionError("No ConstraintsGenerationUtils instance for you");
}
/**
* Generate the constraints for a map of type placeholder and RefType and merge
* these to the already provided constraints.
*
* @param tphMap {@link Map} of {@link TypePlaceholder} and
* {@link RefTypeOrTPHOrWildcardOrGeneric}
* @param constraints {@link ConstraintSet} over {@link Pair} to merge to
* @return The same instance {@code constraints} provided including the merged
* constraints
*/
public static ConstraintSet<Pair> generateAndMergeConstraints (
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap,
ConstraintSet<Pair> constraints) {
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
constraints.addAll(generateConstraints);
return constraints;
}
/**
* Generate the constraints for a map of type placeholder and RefType.
*
* @param tphMap {@link Map} of {@link TypePlaceholder} and
* {@link RefTypeOrTPHOrWildcardOrGeneric}
* @return {@link ConstraintSet} of {@link Pair} containing the constraints to
* infer the matching wildcard type.
*/
public static ConstraintSet<Pair> generateConstraints (
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap) {
return tphMap.entrySet().stream().map(ConstraintsGenerationUtils::generateConstraints)
.reduce(
new ConstraintSet<>(),
(cs, c) -> {
cs.addAll(c);
return cs;
});
}
/**
* Generate the constraints for a single RefType type placeholder pair to infer
* the wildcards for the generic parameter type.
*
* @param tphEntry {@link Entry} of {@link TypePlaceholder} and
* {@link RefTypeOrTPHOrWildcardOrGeneric}
* @return {@link ConstraintSet} of {@link Pair} generated containing the
* constraints.
*/
private static ConstraintSet<Pair> generateConstraints (
Map.Entry<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphEntry) {
return generateConstraints(tphEntry.getValue(), tphEntry.getKey());
}
/**
* Generate the constraints for a single RefType type placeholder pair to infer
* the wildcards for the generic parameter type.
*
* @param refType {@link RefTypeOrTPHOrWildcardOrGeneric}
* @param tph {@link TypePlaceholder}
* @return {@link ConstraintSet} of {@link Pair} generated containing the
* constraints.
*/
public static ConstraintSet<Pair> generateConstraints (RefTypeOrTPHOrWildcardOrGeneric refType,
TypePlaceholder tph) {
ConstraintSet<Pair> constraintSet = new ConstraintSet<>();
Set<Constraint<Pair>> oderConstraints = new HashSet<>();
constraintSet.addOderConstraint(oderConstraints);
// single type
ConstraintsGenerationUtils.addToOderConstraint(oderConstraints, tph, refType);
// extends type
ExtendsWildcardType extendsWildcardType = new ExtendsWildcardType(refType, new NullToken());
ConstraintsGenerationUtils.addToOderConstraint(oderConstraints, tph, extendsWildcardType);
// super type
SuperWildcardType superWildcardType = new SuperWildcardType(refType, new NullToken());
ConstraintsGenerationUtils.addToOderConstraint(oderConstraints, tph, superWildcardType);
return constraintSet;
}
private static void addToOderConstraint (Set<Constraint<Pair>> oderConstraints, TypePlaceholder tph,
RefTypeOrTPHOrWildcardOrGeneric refType) {
Constraint<Pair> c = new Constraint<>();
oderConstraints.add(c);
ConstraintsGenerationUtils.addToConstraint(c, tph, refType);
}
/**
* Generate a pair and adds it to a constraint.
*
* @param c {@link Constraint} of {@link Pair}
* @param tph {@link TypePlaceholder}
* @param type {@link RefTypeOrTPHOrWildcardOrGeneric}
*/
private static void addToConstraint (Constraint<Pair> c, TypePlaceholder tph,
RefTypeOrTPHOrWildcardOrGeneric type) {
Pair pair = new Pair(tph, type, PairOperator.EQUALSDOT);
c.add(pair);
}
}

View File

@@ -0,0 +1,40 @@
package de.dhbwstuttgart.inferWildcards;
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
public class FindInAstVisitor
{
public static boolean find (SourceFile file, TypePlaceholder tph) {
FindInAstVisitor findInAstVisitor = new FindInAstVisitor(tph);
return findInAstVisitor.find(file);
}
private boolean find;
private TypePlaceholder tph;
public FindInAstVisitor (TypePlaceholder tph) {
this.tph = tph;
find = false;
}
public boolean find (SourceFile file) {
CostumASTWalker walker = new CostumASTWalker();
walker.visit(file);
return find;
}
private class CostumASTWalker extends AbstractASTWalker{
@Override
public void visit (TypePlaceholder typePlaceholder) {
if (typePlaceholder.equals(tph))
find = true;
else
super.visit(typePlaceholder);
}
}
}

View File

@@ -0,0 +1,209 @@
package de.dhbwstuttgart.inferWildcards;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.antlr.v4.runtime.Token;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.ResolvedType;
import de.dhbwstuttgart.typeinference.result.ResultSet;
/**
* Extension of the JavaTX Compiler providing the capabilities to inference
* wildcard types.
* <p>
* <code>
* <ul>
* <li>? super Type</li>
* <li>? extends Type</li>
* <li>Type</li>
* </ul>
* </code>
*
* @author Till Schnell
* @version 1.0
*/
public class JavaTXCompilerWildcards
extends JavaTXCompiler
{
/**
* Generated Type placeholder and the implementation type represented.
*/
private final Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap;
public JavaTXCompilerWildcards (File... sourceFile) throws IOException, ClassNotFoundException {
super(Arrays.asList(sourceFile));
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
}
public JavaTXCompilerWildcards (File sourceFile, Boolean log) throws IOException, ClassNotFoundException {
super(sourceFile, log);
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
}
public JavaTXCompilerWildcards (List<File> sourceFiles) throws IOException, ClassNotFoundException {
super(sourceFiles);
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
}
public JavaTXCompilerWildcards (List<File> sources, List<File> contextPath)
throws IOException, ClassNotFoundException {
super(sources, contextPath);
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
}
/**
* Return the Type Placeholder generated.
*
* @return {@link Map} over {@link TypePlaceholder} and
* {@link RefTypeOrTPHOrWildcardOrGeneric}
*/
public Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> getTphMap () {
return tphMap;
}
@Override
public ConstraintSet<Pair> getConstraints () throws ClassNotFoundException, IOException {
ConstraintSet<Pair> constraints = super.getConstraints();
return ConstraintsGenerationUtils.generateAndMergeConstraints(tphMap, constraints);
}
/**
* Generate the source code for manipulated Java Generic Types to a new .java
* file.
*
* @param outputDir {@link File}
* @throws IOException if an i/o exception during file reading and
* writing occurs
* @throws ClassNotFoundException see {@link #typeInference()}
*/
public void generateSourceCode (File outputDir) throws IOException, ClassNotFoundException {
if (!outputDir.exists()) {
boolean mkdirs = outputDir.mkdirs();
if (!mkdirs)
throw new IOException("Could not create output directory at: " + outputDir.getAbsolutePath());
}
List<ResultSet> typeInference = typeInference();
if (typeInference.isEmpty())
return;
ResultSet resultSet = typeInference.get(0); // Use the first available result sets
for (Map.Entry<File, SourceFile> e : sourceFiles.entrySet()) {
List<Map.Entry<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric>> list = tphMap.entrySet().stream().filter(d -> FindInAstVisitor.find(e.getValue(), d.getKey())).sorted( (c1, c2) -> Integer.compare(c1.getValue().getOffset().getStartIndex(),
c2.getValue().getOffset().getStartIndex())).collect(Collectors.toList());
generateSourceCode(e.getKey(), outputDir, list, resultSet);
}
}
private void generateSourceCode (File inputFile, File outputDir,
List<Map.Entry<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric>> tphs,
ResultSet results)
throws IOException {
File outputFile = new File(outputDir, inputFile.getName());
Files.deleteIfExists(outputFile.toPath());
if(!outputFile.createNewFile())
throw new IOException("File could not be created at: " + outputFile.getAbsolutePath());
try(BufferedReader reader = new BufferedReader(new FileReader(inputFile));
BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))){
int readIdx = 0;
for (Map.Entry<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> e : tphs) {
Token token = e.getValue().getOffset();
// read the characters before the token
int startIndex = token.getStartIndex();
char[] read = new char[startIndex - readIdx];
int i = reader.read(read);
if (i != read.length)
throw new IOException("Could not read the assumed number of character, read " + i
+ " assumed " + read.length);
readIdx += read.length;
// Write to output file
writer.write(read);
// Write the new type
ResolvedType resolveType = results.resolveType(e.getKey());
String string = resolveType.resolvedType.toString();
writer.write(string);
// Read the replaced type and count the read counter
int length = token.getStopIndex() - token.getStartIndex() + 1;
reader.read(new char[length]);
readIdx += length;
// Read the replaced nested type if the result was a nested type
Pattern pattern = Pattern.compile("<.*>");
Matcher matcher = pattern.matcher(string);
if (matcher.find()) {
// Read the first and check if it will be a Java Generic Expression starting
// with <
char c = (char) reader.read();
readIdx++;
if (c != '<')
throw new IllegalStateException("At this position is a < expected, found " + c);
// Read and forget all content until a > on the same level
int opens = 1;
while (opens > 0) {
c = (char) reader.read();
readIdx++;
switch (c)
{
case '<':
opens++;
break;
case '>':
opens--;
break;
}
}
}
}
// Read the rest of the file.
while (true) {
char[] tmp = new char[1024];
int read = reader.read(tmp);
if (read == -1)
break;
writer.write(tmp, 0, read);
}
}
}
}

View File

@@ -0,0 +1,171 @@
package de.dhbwstuttgart.inferWildcards;
import java.util.HashMap;
import java.util.ListIterator;
import java.util.Map;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
/**
* Visitor replace type parameter of the type RefType by Type Placeholder in a
* AST.
*
* @author Till Schnell
* @version 1.0
*/
public class ReplaceTypeparamVisitor
extends AbstractASTWalker
{
/**
* Containing the replaced RefType and the mapping TPH
*/
private final Map<TypePlaceholder, RefTypeOrTPHOrWildcardOrGeneric> tphMap;
/**
* Constructor for a {@code ReplaceTypeparamVisitor}.
*/
public ReplaceTypeparamVisitor () {
this.tphMap = new HashMap<>();
}
@Override
public void visit (Field field) {
System.out.println("Field: " + field.getName());
field.accept(new ReplaceRefTypeVisitor());
super.visit(field);
}
@Override
public void visit (FormalParameter formalParameter) {
System.out.println("FormalParameter: " + formalParameter.getName());
formalParameter.accept(new ReplaceRefTypeVisitor());
super.visit(formalParameter);
}
@Override
public void visit (LocalVarDecl localVarDecl) {
System.out.println("LocalVarDecl: " + localVarDecl.getName());
localVarDecl.accept(new ReplaceRefTypeVisitor());
super.visit(localVarDecl);
}
@Override
public void visit (Method method) {
System.out.println("Method: " + method.getName());
RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType();
if (returnType != null)
returnType.accept(new ReplaceRefTypeVisitor());
super.visit(method);
}
/**
* Return the mapping of the replaced {@link RefType} and the inserted
* {@link TypePlaceholder}.
*
* @return {@link Map} of {@link TypePlaceholder} and {@link RefType}
*/
public Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> getTphMap () {
return tphMap;
}
/**
* Visitor replace each RefType occurs.
*
* @author Till Schnell
* @version 1.0
*/
private class ReplaceRefTypeVisitor
extends AbstractASTWalker
{
@Override
public void visit (RefType refType) {
// check if RefType has Parameter Types
if (!refType.getParaList().isEmpty()) {
System.out.print("Visit Type: " + refType + " -> ");
// Iterate over all Parameter Types
for (ListIterator<RefTypeOrTPHOrWildcardOrGeneric> listIterator = refType.getParaList()
.listIterator(); listIterator.hasNext();) {
RefTypeOrTPHOrWildcardOrGeneric next = listIterator.next();
// If Parameter type is RefType replace with TPH
if (next instanceof RefType) {
RefType nextRefType = (RefType) next;
// Visit replaced RefType to get all nested type parameters
// Should be done before generating parents TPH to include child TPH in the
// parent TPH mapping
this.visit(nextRefType);
generateTphAndReplaceInTree(listIterator, next);
}
else if (next instanceof GenericRefType) {
// Visit of nested type arguments not necessary as Generic Types cannot contain
// type parameters
generateTphAndReplaceInTree(listIterator, next);
}
}
System.out.println(refType);
}
// Let the parent take care about all the other stuff
super.visit(refType);
}
/**
* Generate the TPH for a {@link RefTypeOrTPHOrWildcardOrGeneric} and saves the
* mapping.
*
* @param t {@link RefTypeOrTPHOrWildcardOrGeneric}
* @return {@link TypePlaceholder} generated
*/
private TypePlaceholder generateTypePlaceholder (RefTypeOrTPHOrWildcardOrGeneric t) {
TypePlaceholder tph = TypePlaceholder.fresh(new NullToken());
tphMap.put(tph, t);
return tph;
}
/**
* Generate the TPH for a {@link RefTypeOrTPHOrWildcardOrGeneric}, saves the
* mapping and replaces the type by the type placeholder in the tree.
*
* @param listIterator {@link ListIterator} over
* {@link RefTypeOrTPHOrWildcardOrGeneric} representing the
* tree to replace in
* @param refType {@link RefTypeOrTPHOrWildcardOrGeneric} to generate type
* placeholder for and replace
*/
private void generateTphAndReplaceInTree (ListIterator<RefTypeOrTPHOrWildcardOrGeneric> listIterator,
RefTypeOrTPHOrWildcardOrGeneric refType) {
// Generate TPH
TypePlaceholder tph = generateTypePlaceholder(refType);
// Replace in AST
listIterator.set(tph);
}
}
}

View File

@@ -0,0 +1,42 @@
package de.dhbwstuttgart.inferWildcards;
import java.io.File;
import java.util.Map;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
/**
* Class providing utilities to generate the Type placeholder for parameter
* types which shall be inferred.
*
* @author Till Schnell
* @version 1.0
*/
public final class TypePlaceholderReplaceUtils
{
private TypePlaceholderReplaceUtils () {
throw new AssertionError("No TypePlaceholderReplaceUtils instance for you");
}
/**
* Return the map of the generated type placeholder for the associate parameter
* type
*
* @param compiler {@link JavaTXCompiler} to get the source file from
* @return {@link Map} over {@link TypePlaceholder} and the {@link RefType}
* replaced
*/
public static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTypePlaceholder (
JavaTXCompiler compiler) {
Map<File, SourceFile> sourceFiles = compiler.sourceFiles;
ReplaceTypeparamVisitor visitor = new ReplaceTypeparamVisitor();
sourceFiles.forEach( (k, v) -> v.accept(visitor));
return visitor.getTphMap();
}
}

View File

@@ -216,6 +216,7 @@ public class StatementGenerator {
MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()), MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()),
getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(methodInvocationContext.getStart()), getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(methodInvocationContext.getStart()),
argTypes, methodInvocationContext.getStart()); argTypes, methodInvocationContext.getStart());
ret.setStatement();
return ret; return ret;
} }
@@ -302,33 +303,45 @@ public class StatementGenerator {
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = args.getArguments().stream() ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = args.getArguments().stream()
.map(x -> TypePlaceholder.fresh(newExpression.getStart())) .map(x -> TypePlaceholder.fresh(newExpression.getStart()))
.collect(Collectors.toCollection(ArrayList::new)); .collect(Collectors.toCollection(ArrayList::new));
return new NewClass(newClass, args, null, argTypes, newExpression.getStart()); Statement ret = new NewClass(newClass, args, null, argTypes, newExpression.getStart());
ret.setStatement();
return ret;
} }
private Statement convert(Java8Parser.PreIncrementExpressionContext stmt) { private Statement convert(Java8Parser.PreIncrementExpressionContext stmt) {
Expression argument = convert(stmt.unaryExpression()); Expression argument = convert(stmt.unaryExpression());
Token offset = stmt.getStart(); Token offset = stmt.getStart();
return new UnaryExpr(UnaryExpr.Operation.PREINCREMENT, argument, TypePlaceholder.fresh(offset), offset); Statement ret = new UnaryExpr(UnaryExpr.Operation.PREINCREMENT, argument, TypePlaceholder.fresh(offset), offset);
} ret.setStatement();
return ret;
}
private Statement convert(Java8Parser.PreDecrementExpressionContext stmt) { private Statement convert(Java8Parser.PreDecrementExpressionContext stmt) {
return new UnaryExpr(UnaryExpr.Operation.PREDECREMENT, convert(stmt.unaryExpression()), Statement ret = new UnaryExpr(UnaryExpr.Operation.PREDECREMENT, convert(stmt.unaryExpression()),
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart()); TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
ret.setStatement();
return ret;
} }
private Statement convert(Java8Parser.PostIncrementExpressionContext stmt) { private Statement convert(Java8Parser.PostIncrementExpressionContext stmt) {
return new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, convert(stmt.postfixExpression()), Statement ret = new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, convert(stmt.postfixExpression()),
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart()); TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
ret.setStatement();
return ret;
} }
private Statement convert(Java8Parser.PostDecrementExpressionContext stmt) { private Statement convert(Java8Parser.PostDecrementExpressionContext stmt) {
return new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, convert(stmt.postfixExpression()), Statement ret = new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, convert(stmt.postfixExpression()),
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart()); TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
ret.setStatement();
return ret;
} }
private Statement convert(Java8Parser.AssignmentContext stmt) { private Statement convert(Java8Parser.AssignmentContext stmt) {
AssignLeftSide leftHandSide = convert(stmt.leftHandSide()); AssignLeftSide leftHandSide = convert(stmt.leftHandSide());
return new Assign(leftHandSide, convert(stmt.expression()), stmt.getStart()); Statement ret = new Assign(leftHandSide, convert(stmt.expression()), stmt.getStart());
ret.setStatement();
return ret;
} }
private AssignLeftSide convert(Java8Parser.LeftHandSideContext leftHandSide) { private AssignLeftSide convert(Java8Parser.LeftHandSideContext leftHandSide) {

View File

@@ -126,6 +126,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{
public void visit(Assign assign) { public void visit(Assign assign) {
assign.lefSide.accept(this); assign.lefSide.accept(this);
assign.rightSide.accept(this); assign.rightSide.accept(this);
assign.rightSide.getType().accept((ASTVisitor) this);
} }
@Override @Override
@@ -186,8 +187,10 @@ public abstract class AbstractASTWalker implements ASTVisitor{
public void visit(MethodCall methodCall) { public void visit(MethodCall methodCall) {
methodCall.receiver.accept(this); methodCall.receiver.accept(this);
methodCall.getArgumentList().accept(this); methodCall.getArgumentList().accept(this);
methodCall.getArgumentList().getArguments().forEach(a -> a.getType().accept((ASTVisitor) this));
} }
@Override @Override
public void visit(NewClass methodCall) { public void visit(NewClass methodCall) {
visit((MethodCall) methodCall); visit((MethodCall) methodCall);
@@ -211,6 +214,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{
@Override @Override
public void visit(Return aReturn) { public void visit(Return aReturn) {
aReturn.retexpr.accept(this); aReturn.retexpr.accept(this);
aReturn.getType().accept((ASTVisitor) this);
} }
@Override @Override

View File

@@ -31,8 +31,14 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
private ExceptionList exceptionlist; private ExceptionList exceptionlist;
private GenericDeclarationList generics; private GenericDeclarationList generics;
private final RefTypeOrTPHOrWildcardOrGeneric returnType; private final RefTypeOrTPHOrWildcardOrGeneric returnType;
public final Boolean isInherited; public final Boolean isInherited;
/*
* its Constraints
* eingefuegt PL 2021-02-15
*/
public final ConstraintSet constraints = new ConstraintSet();
public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block, public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block,
GenericDeclarationList gtvDeclarations, Token offset) { GenericDeclarationList gtvDeclarations, Token offset) {
super(offset); super(offset);
@@ -70,6 +76,10 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
return this.returnType; return this.returnType;
} }
public ConstraintSet getConstraints() {
return this.constraints;
}
@Override @Override
public void accept(ASTVisitor visitor) { public void accept(ASTVisitor visitor) {
visitor.visit(this); visitor.visit(this);

View File

@@ -45,6 +45,12 @@ public class SourceFile extends SyntaxTreeNode{
public List<ClassOrInterface> getClasses() { public List<ClassOrInterface> getClasses() {
return KlassenVektor; return KlassenVektor;
} }
public List<Method> getAllMethods() {
List<Method> ret = new ArrayList<>();
getClasses().forEach(cl -> ret.addAll(cl.getMethods()));
return ret;
}
@Override @Override
public void accept(ASTVisitor visitor) { public void accept(ASTVisitor visitor) {

View File

@@ -36,7 +36,7 @@ public class ASTFactory {
List<Method> methoden = new ArrayList<>(); List<Method> methoden = new ArrayList<>();
List<de.dhbwstuttgart.syntaxtree.Constructor> konstruktoren = new ArrayList<>(); List<de.dhbwstuttgart.syntaxtree.Constructor> konstruktoren = new ArrayList<>();
for(java.lang.reflect.Constructor constructor : jreClass.getConstructors()){ for(java.lang.reflect.Constructor constructor : jreClass.getConstructors()){
konstruktoren.add(createConstructor(constructor, jreClass)); createConstructor(constructor, jreClass).map(c -> konstruktoren.add(c));
} }
Set<java.lang.reflect.Method> allMethods = new HashSet<>(Arrays.asList(jreClass.getMethods())); Set<java.lang.reflect.Method> allMethods = new HashSet<>(Arrays.asList(jreClass.getMethods()));
Set<java.lang.reflect.Method> allDeclaredMethods = new HashSet<>(Arrays.asList(jreClass.getDeclaredMethods())); Set<java.lang.reflect.Method> allDeclaredMethods = new HashSet<>(Arrays.asList(jreClass.getDeclaredMethods()));
@@ -87,7 +87,7 @@ public class ASTFactory {
// return createClass(classType).getType(); // return createClass(classType).getType();
//} //}
private static de.dhbwstuttgart.syntaxtree.Constructor createConstructor(Constructor constructor, Class inClass) { private static Optional<de.dhbwstuttgart.syntaxtree.Constructor> createConstructor(Constructor constructor, Class inClass) {
String name = constructor.getName(); String name = constructor.getName();
RefTypeOrTPHOrWildcardOrGeneric returnType = createType(inClass); RefTypeOrTPHOrWildcardOrGeneric returnType = createType(inClass);
Parameter[] jreParams = constructor.getParameters(); Parameter[] jreParams = constructor.getParameters();
@@ -106,10 +106,10 @@ public class ASTFactory {
int modifier = constructor.getModifiers(); int modifier = constructor.getModifiers();
if(inClass.equals(java.lang.Object.class)){ if(inClass.equals(java.lang.Object.class)){
return null; return Optional.empty();
} }
return new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset /*, new ArrayList<>() geloescht PL 2018-11-24 */); return Optional.of(new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset /*, new ArrayList<>() geloescht PL 2018-11-24 */));
} }
public static Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass, Boolean isInherited){ public static Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass, Boolean isInherited){

View File

@@ -4,6 +4,16 @@ public class NameGenerator {
private static String strNextName = "A"; private static String strNextName = "A";
/**
* Setzt den zu Beginn der Typinferenz auf "A" zurueck.
* Dies ist bei JUnit-Test noetig
* <code>TypePlaceholder</code>. <br>Author: Martin Pluemicke
* @return void
*/
public static void reset() {
strNextName = "A";
}
/** /**
* Berechnet einen neuen, eindeutigen Namen f�r eine neue * Berechnet einen neuen, eindeutigen Namen f�r eine neue
* <code>TypePlaceholder</code>. <br>Author: J�rg B�uerle * <code>TypePlaceholder</code>. <br>Author: J�rg B�uerle

View File

@@ -18,6 +18,7 @@ import de.dhbwstuttgart.syntaxtree.type.WildcardType;
import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.PairNoResult;
import de.dhbwstuttgart.typeinference.result.PairTPHEqualTPH; import de.dhbwstuttgart.typeinference.result.PairTPHEqualTPH;
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType; import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH; import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH;
@@ -154,7 +155,7 @@ public class UnifyTypeFactory {
public static Constraint<UnifyPair> convert(Constraint<Pair> constraint){ public static Constraint<UnifyPair> convert(Constraint<Pair> constraint){
Constraint<UnifyPair> unifyPairConstraint = constraint.stream() Constraint<UnifyPair> unifyPairConstraint = constraint.stream()
.map(UnifyTypeFactory::convert) .map(UnifyTypeFactory::convert)
.collect(Collectors.toCollection( () -> new Constraint<UnifyPair>(convert(constraint.getExtendConstraint())))); .collect(Collectors.toCollection( () -> new Constraint<UnifyPair> (constraint.isInherited(), convert(constraint.getExtendConstraint()))));
return unifyPairConstraint; return unifyPairConstraint;
} }
@@ -208,6 +209,7 @@ public class UnifyTypeFactory {
} }
public static ResultPair convert(UnifyPair mp, Map<String,TypePlaceholder> tphs) { public static ResultPair convert(UnifyPair mp, Map<String,TypePlaceholder> tphs) {
if (mp == null) { return null;} //kann bei basePairs passieren
RefTypeOrTPHOrWildcardOrGeneric tl = UnifyTypeFactory.convert(mp.getLhsType(), tphs); RefTypeOrTPHOrWildcardOrGeneric tl = UnifyTypeFactory.convert(mp.getLhsType(), tphs);
RefTypeOrTPHOrWildcardOrGeneric tr = UnifyTypeFactory.convert(mp.getRhsType(), tphs); RefTypeOrTPHOrWildcardOrGeneric tr = UnifyTypeFactory.convert(mp.getRhsType(), tphs);
if(tl instanceof TypePlaceholder){ if(tl instanceof TypePlaceholder){
@@ -218,7 +220,7 @@ public class UnifyTypeFactory {
//Einfach ignorieren TODO: Das hier muss ausgebessert werden: //Einfach ignorieren TODO: Das hier muss ausgebessert werden:
//return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, ASTFactory.createObjectType()); //return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, ASTFactory.createObjectType());
}else{ }else{
return new PairTPHsmallerTPH((TypePlaceholder)tl, (TypePlaceholder)tr); return new PairTPHsmallerTPH((TypePlaceholder)tl, (TypePlaceholder)tr, convert(mp.getBasePair(), tphs));
} }
}else if(tr instanceof RefType){ }else if(tr instanceof RefType){
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (RefType) tr); return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (RefType) tr);
@@ -227,7 +229,7 @@ public class UnifyTypeFactory {
}else if(tr instanceof GenericRefType){ }else if(tr instanceof GenericRefType){
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (GenericRefType) tr); return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (GenericRefType) tr);
}else throw new NotImplementedException(); }else throw new NotImplementedException();
}else throw new NotImplementedException(); }else return new PairNoResult(tl, tr);//throw new NotImplementedException();
} }
public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map<String,TypePlaceholder> tphs) { public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map<String,TypePlaceholder> tphs) {
@@ -258,6 +260,7 @@ public class UnifyTypeFactory {
ret = TypePlaceholder.fresh(new NullToken()); ret = TypePlaceholder.fresh(new NullToken());
tphs.put(t.getName(), ret); tphs.put(t.getName(), ret);
} }
ret.setVariance(t.getVariance());
return ret; return ret;
} }

View File

@@ -24,13 +24,9 @@ public class MethodCall extends Statement
public final ArgumentList arglist; public final ArgumentList arglist;
/*
* noetig fuer Bytecodegenerierung
*/
public RefTypeOrTPHOrWildcardOrGeneric receiverType; public RefTypeOrTPHOrWildcardOrGeneric receiverType;
public final ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes; public final ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes;
public MethodCall(RefTypeOrTPHOrWildcardOrGeneric retType, Receiver receiver, String methodName, ArgumentList argumentList, public MethodCall(RefTypeOrTPHOrWildcardOrGeneric retType, Receiver receiver, String methodName, ArgumentList argumentList,
RefTypeOrTPHOrWildcardOrGeneric receiverType, ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token offset){ RefTypeOrTPHOrWildcardOrGeneric receiverType, ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token offset){
super(retType,offset); super(retType,offset);
@@ -40,6 +36,7 @@ public class MethodCall extends Statement
this.receiverType = receiverType; this.receiverType = receiverType;
this.argTypes = argTypes; this.argTypes = argTypes;
} }
@Override @Override
public void accept(StatementVisitor visitor) { public void accept(StatementVisitor visitor) {

View File

@@ -6,11 +6,20 @@ import org.antlr.v4.runtime.Token;
public abstract class Statement extends Expression public abstract class Statement extends Expression
{ {
/* zeigt an, dass eine StatementExpression als Statement benutzt wird
*/
private boolean isStatement = false;
public Statement(RefTypeOrTPHOrWildcardOrGeneric type, Token offset) public Statement(RefTypeOrTPHOrWildcardOrGeneric type, Token offset)
{ {
super(type, offset); super(type, offset);
} }
public void setStatement() {
isStatement=true;
}
public boolean getStatement() {
return isStatement;
}
} }

View File

@@ -53,4 +53,10 @@ public class ExtendsWildcardType extends WildcardType{
public void accept(ResultSetVisitor visitor) { public void accept(ResultSetVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
@Override
public boolean equals(Object o) {
// TODO Auto-generated method stub
return false;
}
} }

View File

@@ -32,5 +32,18 @@ public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
public void accept(ResultSetVisitor visitor) { public void accept(ResultSetVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
@Override
public boolean equals(Object o) {
// TODO Auto-generated method stub
return false;
}
@Override
public String toString()
{
return "GTV " + this.name;
}
} }

View File

@@ -77,8 +77,8 @@ public class RefType extends RefTypeOrTPHOrWildcardOrGeneric
if(obj instanceof RefType){ if(obj instanceof RefType){
boolean ret = true; boolean ret = true;
if(!super.equals(obj)) //if(!(super.equals(obj))) PL 2020-03-12 muss vll. einkommentiert werden
return false; // return false;
if(parameter==null || parameter.size()==0){ if(parameter==null || parameter.size()==0){
ret &= (((RefType)obj).getParaList()==null || ((RefType)obj).getParaList().size()==0); ret &= (((RefType)obj).getParaList()==null || ((RefType)obj).getParaList().size()==0);

View File

@@ -16,4 +16,7 @@ public abstract class RefTypeOrTPHOrWildcardOrGeneric extends SyntaxTreeNode{
public abstract <A> A acceptTV(TypeVisitor<A> visitor); public abstract <A> A acceptTV(TypeVisitor<A> visitor);
public abstract void accept(ResultSetVisitor visitor); public abstract void accept(ResultSetVisitor visitor);
@Override
public abstract boolean equals(Object o);
} }

View File

@@ -64,4 +64,10 @@ public class SuperWildcardType extends WildcardType{
public void accept(ResultSetVisitor visitor) { public void accept(ResultSetVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
@Override
public boolean equals(Object o) {
// TODO Auto-generated method stub
return false;
}
} }

View File

@@ -20,10 +20,9 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
private final String name; private final String name;
/** /**
* wird bisher nicht genutzt * wird im Generate Generics Teil nach der Rueckumwandlung nach dem Unify genutzt
* setVariance muss ggf. auskommentiert werden.
*/ */
int variance = 0; private int variance = 0;
/** /**
@@ -78,11 +77,9 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
return name; return name;
} }
/* wird bisher nicht genutzt
public void setVariance(int variance) { public void setVariance(int variance) {
this.variance= variance; this.variance= variance;
} }
*/
public int getVariance() { public int getVariance() {
return this.variance; return this.variance;

View File

@@ -17,13 +17,15 @@ public class MethodAssumption extends Assumption{
private ClassOrInterface receiver; private ClassOrInterface receiver;
private RefTypeOrTPHOrWildcardOrGeneric retType; private RefTypeOrTPHOrWildcardOrGeneric retType;
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params; List<? extends RefTypeOrTPHOrWildcardOrGeneric> params;
private final Boolean isInherited;
public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType, public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType,
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope){ List<? extends RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope, Boolean isInherited){
super(scope); super(scope);
this.receiver = receiver; this.receiver = receiver;
this.retType = retType; this.retType = retType;
this.params = params; this.params = params;
this.isInherited = isInherited;
} }
/* /*
@@ -70,4 +72,8 @@ public class MethodAssumption extends Assumption{
return receiverType; return receiverType;
} }
public Boolean isInherited() {
return isInherited;
}
} }

View File

@@ -6,17 +6,38 @@ import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
//TODO: Remove this class
public class Constraint<A> extends HashSet<A> { public class Constraint<A> extends HashSet<A> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Constraint<A> extendConstraint = null; private Boolean isInherited = false;//wird nur für die Method-Constraints benoetigt
public Constraint(){}
public Constraint(Constraint<A> extendConstraint) { /* es darf kein Constraint für den Return-Type erstellt werden, sonst gibt
* es Probleme beim Generated Generics
*/
public boolean isStatement = false;
private Constraint<A> extendConstraint = null;
public Constraint() {
super();
}
public Constraint(Boolean isInherited) {
this.isInherited = isInherited;
}
public Constraint(Boolean isInherited, Constraint<A> extendConstraint) {
this.isInherited = isInherited;
this.extendConstraint = extendConstraint; this.extendConstraint = extendConstraint;
} }
public void setIsInherited(Boolean isInherited) {
this.isInherited = isInherited;
}
public Boolean isInherited() {
return isInherited;
}
public Constraint<A> getExtendConstraint() { public Constraint<A> getExtendConstraint() {
return extendConstraint; return extendConstraint;
} }
@@ -26,7 +47,7 @@ public class Constraint<A> extends HashSet<A> {
} }
public String toString() { public String toString() {
return super.toString() return super.toString() + "\nisInherited = " + isInherited + "\nisStatement = " + isStatement
//" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" ) //" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" )
+ "\n" ; + "\n" ;
} }

View File

@@ -23,9 +23,17 @@ public class ConstraintSet<A> {
oderConstraints.add(methodConstraints); oderConstraints.add(methodConstraints);
} }
public void addAllUndConstraint(Constraint<A> allUndConstraints){
undConstraints.addAll(allUndConstraints);
}
public void addAllOderConstraint(List<Set<Constraint<A>>> allOderConstraints){
this.oderConstraints.addAll(allOderConstraints);
}
public void addAll(ConstraintSet constraints) { public void addAll(ConstraintSet constraints) {
this.undConstraints.addAll(constraints.undConstraints); this.addAllUndConstraint(constraints.undConstraints);
this.oderConstraints.addAll(constraints.oderConstraints); this.addAllOderConstraint(constraints.oderConstraints);
} }
@Override @Override
@@ -68,8 +76,9 @@ public class ConstraintSet<A> {
Constraint<B> newConst = as.stream() Constraint<B> newConst = as.stream()
.map(o) .map(o)
.collect(Collectors.toCollection((as.getExtendConstraint() != null) .collect(Collectors.toCollection((as.getExtendConstraint() != null)
? () -> new Constraint<B> (as.getExtendConstraint().stream().map(o).collect(Collectors.toCollection(Constraint::new))) ? () -> new Constraint<B> (as.isInherited(),
: () -> new Constraint<B> () as.getExtendConstraint().stream().map(o).collect(Collectors.toCollection(Constraint::new)))
: () -> new Constraint<B> (as.isInherited())
)); ));
//CSA2CSB.put(as, newConst); //CSA2CSB.put(as, newConst);

View File

@@ -1,107 +0,0 @@
package de.dhbwstuttgart.typeinference.constraints;
import java.util.*;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public class ConstraintSet2 {
Set<OderConstraint> oderConstraints = new HashSet<>();
public ConstraintSet2(Set<OderConstraint> constraints){
if(constraints.isEmpty())throw new RuntimeException("Empty constraint set");
this.oderConstraints = constraints;
}
@Override
public String toString(){
BinaryOperator<String> b = (x,y) -> x+y;
return "ODER:" + this.oderConstraints.stream().reduce("", (x,y) -> x.toString()+ "\n" +y, b);
}
private class ConstraintSpliterator implements Spliterator<Set<Pair>> {
private List<OderConstraint> constraints;
private long i = 0;
private long max = 0;
private List<Integer> sizes;
private List<Long> bases = new ArrayList<>();
ConstraintSpliterator(List<OderConstraint> constraints){
this.constraints = constraints;
sizes = constraints.stream().map(OderConstraint::getSize).collect(Collectors.toList());
long base = 1;
for(int size : sizes){
bases.add(base);
base *= size;
}
i = 0;
max = estimateSize() - 1;
}
ConstraintSpliterator(List<OderConstraint> constraints, long start, long end){
this(constraints);
i = start;
max = end;
}
@Override
public boolean tryAdvance(Consumer<? super Set<Pair>> consumer) {
if(i > max) return false;
consumer.accept(get(i));
i++;
return true;
}
private Set<Pair> get(long num){
Set<Pair> ret = new HashSet<>();
Iterator<Long> baseIt = bases.iterator();
for(OderConstraint constraint : constraints){
ret.addAll(constraint.get((int) ((num/baseIt.next())%constraint.getSize())));
}
return ret;
}
@Override
public Spliterator<Set<Pair>> trySplit() {
if(max - i < 2) return null;
long middle = i + ((max- i) / 2);
long maxOld = max;
max = middle - 1;
return new ConstraintSpliterator(constraints, middle, maxOld);
}
@Override
public long estimateSize() {
long ret = 1;
for (int size : sizes)ret*=size;
return ret;
}
@Override
public int characteristics() {
return ORDERED | SIZED | IMMUTABLE | NONNULL;
}
}
public Stream<Set<Pair>> cartesianProductParallel(){
return StreamSupport.stream(new ConstraintSpliterator(oderConstraints.stream().collect(Collectors.toList())), true);
}
/*
public Map<String, TypePlaceholder> generateTPHMap() {
HashMap<String, TypePlaceholder> ret = new HashMap<>();
constraints.map((Pair p) -> {
if (p.TA1 instanceof TypePlaceholder) {
ret.put(((TypePlaceholder) p.TA1).getName(), (TypePlaceholder) p.TA1);
}
if (p.TA2 instanceof TypePlaceholder) {
ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2);
}
return null;
});
return ret;
}
*/
}

View File

@@ -1,26 +0,0 @@
package de.dhbwstuttgart.typeinference.constraints;
import java.util.HashSet;
import java.util.Set;
public class ConstraintSetBuilder {
private Set<Pair> undConstraints = new HashSet<>();
private Set<OderConstraint> oderConstraints = new HashSet<>();
private boolean done = false;
public void addUndConstraint(Pair p){
undConstraints.add(p);
}
public void addOderConstraint(OderConstraint orConstraint) {
oderConstraints.add(orConstraint);
}
public ConstraintSet2 build(){
if(done)throw new RuntimeException("Trying to build cartesian product twice");
this.done = true;
if(!undConstraints.isEmpty())
oderConstraints.add(new OderConstraint(Set.of(undConstraints)));
return new ConstraintSet2(oderConstraints);
}
}

View File

@@ -1,24 +0,0 @@
package de.dhbwstuttgart.typeinference.constraints;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class OderConstraint {
private final List<Set<Pair>> cons;
public OderConstraint(Set<Set<Pair>> orCons){
if(orCons.isEmpty())throw new RuntimeException("Empty constraint set");
for(Set<Pair> c : orCons){
if(c.isEmpty())throw new RuntimeException("Empty constraint set");
}
this.cons = orCons.stream().collect(Collectors.toList());
}
public int getSize(){
return cons.size();
}
public Set<Pair> get(int l) {
return cons.get(l);
}
}

View File

@@ -0,0 +1,32 @@
package de.dhbwstuttgart.typeinference.result;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
/**
* enthaelt alle Paare, die in einem Ergebnis nicht vorkommen koennen
* sie sind noetig fuer origPairs in PairTPHsmallerTPH, da hier auch
* Paare vorkommen koennen die keine Result sind (z.B. bei FunN$$)
*/
public class PairNoResult extends ResultPair<RefTypeOrTPHOrWildcardOrGeneric, RefTypeOrTPHOrWildcardOrGeneric>{
//public final TypePlaceholder left;
//public final TypePlaceholder right;
/*
* urspruengliches Paar aus diesem dieses Resultpair erzeugt wurde
* wichtig fuer generated Generics
*/
ResultPair origPair;
public PairNoResult(RefTypeOrTPHOrWildcardOrGeneric left, RefTypeOrTPHOrWildcardOrGeneric right){
super(left, right);
}
/* noch nicht implementiert. */
@Override
public void accept(ResultPairVisitor visitor) {
throw new NotImplementedException();
//visitor.visit(this);
}
}

View File

@@ -9,6 +9,12 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
public class PairTPHsmallerTPH extends ResultPair{ public class PairTPHsmallerTPH extends ResultPair{
public final TypePlaceholder left; public final TypePlaceholder left;
public final TypePlaceholder right; public final TypePlaceholder right;
/*
* urspruengliches Paar aus diesem dieses Resultpair erzeugt wurde
* wichtig fuer generated Generics
*/
ResultPair origPair;
public PairTPHsmallerTPH(TypePlaceholder left, TypePlaceholder right){ public PairTPHsmallerTPH(TypePlaceholder left, TypePlaceholder right){
super(left, right); super(left, right);
@@ -16,6 +22,11 @@ public class PairTPHsmallerTPH extends ResultPair{
this.right = right; this.right = right;
} }
public PairTPHsmallerTPH(TypePlaceholder left, TypePlaceholder right, ResultPair origPair){
this(left, right);
this.origPair = origPair;
}
@Override @Override
public void accept(ResultPairVisitor visitor) { public void accept(ResultPairVisitor visitor) {
visitor.visit(this); visitor.visit(this);

View File

@@ -4,4 +4,7 @@ public interface ResultPairVisitor {
void visit(PairTPHsmallerTPH p); void visit(PairTPHsmallerTPH p);
void visit(PairTPHequalRefTypeOrWildcardType p); void visit(PairTPHequalRefTypeOrWildcardType p);
void visit(PairTPHEqualTPH p); void visit(PairTPHEqualTPH p);
//bisher nicht umgesetzt
//void visit(PairNoResult p);
} }

View File

@@ -32,8 +32,10 @@ public class TYPE {
private ConstraintSet getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) { private ConstraintSet getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) {
ConstraintSet ret = new ConstraintSet(); ConstraintSet ret = new ConstraintSet();
ConstraintSet methConstrains;
for(Method m : cl.getMethods()){ for(Method m : cl.getMethods()){
ret.addAll(getConstraintsMethod(m,info, cl)); ret.addAll(methConstrains = getConstraintsMethod(m,info, cl));
m.constraints.addAll(methConstrains);
} }
for(Constructor m : cl.getConstructors()){ for(Constructor m : cl.getConstructors()){
ret.addAll(getConstraintsConstructor(m,info, cl)); ret.addAll(getConstraintsConstructor(m,info, cl));

View File

@@ -11,6 +11,7 @@ import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator; import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
import de.dhbwstuttgart.syntaxtree.statement.*; import de.dhbwstuttgart.syntaxtree.statement.*;
import de.dhbwstuttgart.syntaxtree.type.*; import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption; import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
import de.dhbwstuttgart.typeinference.assumptions.FunNClass; import de.dhbwstuttgart.typeinference.assumptions.FunNClass;
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption; import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
@@ -179,7 +180,8 @@ public class TYPEStmt implements StatementVisitor{
!(x.TA2 instanceof TypePlaceholder)) !(x.TA2 instanceof TypePlaceholder))
? new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT) ? new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT)
: x) : x)
.collect(Collectors.toCollection(() -> new Constraint<Pair>())); .collect(Collectors.toCollection(() -> new Constraint<Pair>(oneMethodConstraint.isInherited())));
extendsOneMethodConstraint.isStatement = oneMethodConstraint.isStatement;
oneMethodConstraint.setExtendConstraint(extendsOneMethodConstraint); oneMethodConstraint.setExtendConstraint(extendsOneMethodConstraint);
extendsOneMethodConstraint.setExtendConstraint(oneMethodConstraint); extendsOneMethodConstraint.setExtendConstraint(oneMethodConstraint);
methodConstraints.add(extendsOneMethodConstraint); methodConstraints.add(extendsOneMethodConstraint);
@@ -490,7 +492,7 @@ public class TYPEStmt implements StatementVisitor{
@Override @Override
public void visit(Return returnExpr) { public void visit(Return returnExpr) {
returnExpr.retexpr.accept(this); returnExpr.retexpr.accept(this);
constraintsSet.addUndConstraint(new Pair(returnExpr.getType(),info.getCurrentTypeScope().getReturnType(), PairOperator.SMALLERDOT)); constraintsSet.addUndConstraint(new Pair(returnExpr.getType(),info.getCurrentTypeScope().getReturnType(), PairOperator.EQUALSDOT));
} }
@Override @Override
@@ -574,7 +576,7 @@ public class TYPEStmt implements StatementVisitor{
protected Constraint<Pair> generateConstraint(MethodCall forMethod, MethodAssumption assumption, protected Constraint<Pair> generateConstraint(MethodCall forMethod, MethodAssumption assumption,
TypeInferenceBlockInformation info, GenericsResolver resolver){ TypeInferenceBlockInformation info, GenericsResolver resolver){
Constraint<Pair> methodConstraint = new Constraint<>(); Constraint<Pair> methodConstraint = new Constraint<>(assumption.isInherited());
ClassOrInterface receiverCl = assumption.getReceiver(); ClassOrInterface receiverCl = assumption.getReceiver();
/* /*
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
@@ -587,12 +589,18 @@ public class TYPEStmt implements StatementVisitor{
*/ */
RefTypeOrTPHOrWildcardOrGeneric retType = assumption.getReceiverType(resolver); RefTypeOrTPHOrWildcardOrGeneric retType = assumption.getReceiverType(resolver);
methodConstraint.add(forMethod.name.equals("apply") ? //PL 2019-11-29: Tenaerer Operator eingefügt, weil bei Lambda-Ausdrücken keine Suntype FunN$$ existiert methodConstraint.add(new Pair(forMethod.receiver.getType(), retType,
new Pair(forMethod.receiver.getType(), retType, PairOperator.EQUALSDOT) PairOperator.EQUALSDOT));//PL 2020-03-17 SMALLERDOT in EQUALSDOT umgewandelt, weil alle geerbten Methoden in den jeweilen Klassen enthalten sind.
: new Pair(forMethod.receiver.getType(), retType, PairOperator.SMALLERDOT));
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ANFANG
//methodConstraint.add(new Pair(forMethod.receiverType, retType,
// PairOperator.EQUALSDOT));
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE
methodConstraint.isStatement = forMethod.getStatement();
methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(),
PairOperator.EQUALSDOT)); PairOperator.EQUALSDOT));
methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver)); methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver));
return methodConstraint; return methodConstraint;
} }
@@ -636,7 +644,7 @@ public class TYPEStmt implements StatementVisitor{
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() { public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
throw new NotImplementedException(); throw new NotImplementedException();
} }
})); }, false));
} }
for(ClassOrInterface cl : info.getAvailableClasses()){ for(ClassOrInterface cl : info.getAvailableClasses()){
for(Method m : cl.getMethods()){ for(Method m : cl.getMethods()){
@@ -645,7 +653,7 @@ public class TYPEStmt implements StatementVisitor{
RefTypeOrTPHOrWildcardOrGeneric retType = m.getReturnType();//info.checkGTV(m.getReturnType()); RefTypeOrTPHOrWildcardOrGeneric retType = m.getReturnType();//info.checkGTV(m.getReturnType());
ret.add(new MethodAssumption(cl, retType, convertParams(m.getParameterList(),info), ret.add(new MethodAssumption(cl, retType, convertParams(m.getParameterList(),info),
createTypeScope(cl, m))); createTypeScope(cl, m), m.isInherited));
} }
} }
} }
@@ -680,7 +688,7 @@ public class TYPEStmt implements StatementVisitor{
for(Method m : cl.getConstructors()){ for(Method m : cl.getConstructors()){
if(m.getParameterList().getFormalparalist().size() == argList.getArguments().size()){ if(m.getParameterList().getFormalparalist().size() == argList.getArguments().size()){
ret.add(new MethodAssumption(cl, ofType, convertParams(m.getParameterList(), ret.add(new MethodAssumption(cl, ofType, convertParams(m.getParameterList(),
info), createTypeScope(cl, m))); info), createTypeScope(cl, m), m.isInherited));
} }
} }
} }

View File

@@ -655,7 +655,6 @@ public class RuleSet implements IRuleSet{
else else
t1.getTypeParams().forEach(x -> occuringTypes.push(x)); t1.getTypeParams().forEach(x -> occuringTypes.push(x));
} }
Queue<UnifyPair> result1 = new LinkedList<UnifyPair>(pairs); Queue<UnifyPair> result1 = new LinkedList<UnifyPair>(pairs);
ArrayList<UnifyPair> result = new ArrayList<UnifyPair>(); ArrayList<UnifyPair> result = new ArrayList<UnifyPair>();
boolean applied = false; boolean applied = false;
@@ -669,6 +668,7 @@ public class RuleSet implements IRuleSet{
&& pair.getLhsType() instanceof PlaceholderType) && pair.getLhsType() instanceof PlaceholderType)
lhsType = (PlaceholderType) pair.getLhsType(); lhsType = (PlaceholderType) pair.getLhsType();
rhsType = pair.getRhsType(); //PL eingefuegt 2017-09-29 statt !((rhsType = pair.getRhsType()) instanceof PlaceholderType) rhsType = pair.getRhsType(); //PL eingefuegt 2017-09-29 statt !((rhsType = pair.getRhsType()) instanceof PlaceholderType)
if(lhsType != null if(lhsType != null
//&& !((rhsType = pair.getRhsType()) instanceof PlaceholderType) //PL geloescht am 2017-09-29 Begründung: auch Typvariablen muessen ersetzt werden. //&& !((rhsType = pair.getRhsType()) instanceof PlaceholderType) //PL geloescht am 2017-09-29 Begründung: auch Typvariablen muessen ersetzt werden.
&& typeMap.get(lhsType) > 1 // The type occurs in more pairs in the set than just the recent pair. && typeMap.get(lhsType) > 1 // The type occurs in more pairs in the set than just the recent pair.
@@ -682,8 +682,9 @@ public class RuleSet implements IRuleSet{
Function<? super Constraint<UnifyPair>,? extends Constraint<UnifyPair>> applyUni = b -> b.stream().map( Function<? super Constraint<UnifyPair>,? extends Constraint<UnifyPair>> applyUni = b -> b.stream().map(
x -> uni.apply(pair,x)).collect(Collectors.toCollection((b.getExtendConstraint() != null) x -> uni.apply(pair,x)).collect(Collectors.toCollection((b.getExtendConstraint() != null)
? () -> new Constraint<UnifyPair>( ? () -> new Constraint<UnifyPair>(
b.isInherited(),
b.getExtendConstraint().stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(Constraint::new))) b.getExtendConstraint().stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(Constraint::new)))
: () -> new Constraint<UnifyPair>() : () -> new Constraint<UnifyPair>(b.isInherited())
)); ));
oderConstraints.replaceAll(oc -> oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new))); oderConstraints.replaceAll(oc -> oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new)));
/* /*

View File

@@ -34,7 +34,7 @@ public class TypeUnify2Task extends TypeUnifyTask {
System.out.println("two"); System.out.println("two");
} }
one = true; one = true;
Set<Set<UnifyPair>> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField, true); Set<Set<UnifyPair>> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField);
/*if (isUndefinedPairSetSet(res)) { /*if (isUndefinedPairSetSet(res)) {
return new HashSet<>(); } return new HashSet<>(); }
else else

View File

@@ -110,6 +110,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
protected boolean parallel; protected boolean parallel;
//Gives if unify is not called from checkA
private boolean finalresult = true;
int rekTiefeField; int rekTiefeField;
Integer nOfUnify = 0; Integer nOfUnify = 0;
@@ -257,7 +260,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
ArrayList<Set<Constraint<UnifyPair>>> remainingOderconstraints = oderConstraintsField.stream() ArrayList<Set<Constraint<UnifyPair>>> remainingOderconstraints = oderConstraintsField.stream()
.filter(x -> x.size()>1) .filter(x -> x.size()>1)
.collect(Collectors.toCollection(ArrayList::new)); .collect(Collectors.toCollection(ArrayList::new));
Set<Set<UnifyPair>> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, true); Set<Set<UnifyPair>> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField);
noOfThread--; noOfThread--;
try { try {
logFile.close(); logFile.close();
@@ -266,6 +269,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
System.err.println("no log-File"); System.err.println("no log-File");
} }
if (isUndefinedPairSetSet(res)) { if (isUndefinedPairSetSet(res)) {
//fuer debug-Zwecke
ArrayList al = res.stream().map(x -> x.stream().collect(Collectors.toCollection(ArrayList::new)))
.collect(Collectors.toCollection(ArrayList::new));
throw new TypeinferenceException("Unresolved constraints: " + res.toString(), new NullToken()); //return new HashSet<>(); throw new TypeinferenceException("Unresolved constraints: " + res.toString(), new NullToken()); //return new HashSet<>();
} }
else { else {
@@ -299,7 +305,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
* @param fc The finite closure * @param fc The finite closure
* @return The set of all principal type unifiers * @return The set of all principal type unifiers
*/ */
protected Set<Set<UnifyPair>> unify(final Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { protected Set<Set<UnifyPair>> unify(final Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) {
//Set<UnifyPair> aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT) //Set<UnifyPair> aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT)
// ).collect(Collectors.toCollection(HashSet::new)); // ).collect(Collectors.toCollection(HashSet::new));
//writeLog(nOfUnify.toString() + " AA: " + aas.toString()); //writeLog(nOfUnify.toString() + " AA: " + aas.toString());
@@ -308,9 +314,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//} //}
//.collect(Collectors.toCollection(HashSet::new))); //.collect(Collectors.toCollection(HashSet::new)));
/*
* Step 1: Repeated application of reduce, adapt, erase, swap
*/
synchronized (usedTasks) { synchronized (usedTasks) {
if (this.myIsCancelled()) { if (this.myIsCancelled()) {
return new HashSet<>(); return new HashSet<>();
@@ -339,6 +343,29 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
return ret; return ret;
} }
/*
* Occurs-Check durchfuehren
*/
Set<UnifyPair> ocurrPairs = eq.stream().filter(x -> {
UnifyType lhs, rhs;
return (lhs = x.getLhsType()) instanceof PlaceholderType
&& !((rhs = x.getRhsType()) instanceof PlaceholderType)
&& rhs.getTypeParams().occurs((PlaceholderType)lhs);})
.map(x -> { x.setUndefinedPair(); return x;})
.collect(Collectors.toCollection(HashSet::new));
writeLog("ocurrPairs: " + ocurrPairs);
if (ocurrPairs.size() > 0) {
Set<Set<UnifyPair>> ret = new HashSet<>();
ret.add(ocurrPairs);
return ret;
}
/*
* Step 1: Repeated application of reduce, adapt, erase, swap
*/
Set<UnifyPair> eq0; Set<UnifyPair> eq0;
Set<UnifyPair> eq0Prime; Set<UnifyPair> eq0Prime;
Optional<Set<UnifyPair>> eqSubst = Optional.of(eq); Optional<Set<UnifyPair>> eqSubst = Optional.of(eq);
@@ -457,12 +484,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//Aufruf von computeCartesianRecursive ANFANG //Aufruf von computeCartesianRecursive ANFANG
//writeLog("topLevelSets: " + topLevelSets.toString()); //writeLog("topLevelSets: " + topLevelSets.toString());
return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe, finalresult); return computeCartesianRecursive(new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe);
} }
Set<Set<UnifyPair>> unify2(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { Set<Set<UnifyPair>> unify2(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) {
//Aufruf von computeCartesianRecursive ENDE //Aufruf von computeCartesianRecursive ENDE
//keine Ahnung woher das kommt //keine Ahnung woher das kommt
@@ -551,12 +578,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
} }
else if(eqPrimePrime.isPresent()) { else if(eqPrimePrime.isPresent()) {
Set<Set<UnifyPair>> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe, finalresult); Set<Set<UnifyPair>> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe);
eqPrimePrimeSet.addAll(unifyres); eqPrimePrimeSet.addAll(unifyres);
} }
else { else {
Set<Set<UnifyPair>> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe, finalresult); Set<Set<UnifyPair>> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe);
eqPrimePrimeSet.addAll(unifyres); eqPrimePrimeSet.addAll(unifyres);
@@ -587,22 +614,36 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
/**
Set<Set<UnifyPair>> computeCartesianRecursive(Set<Set<UnifyPair>> fstElems, ArrayList<Set<? extends Set<UnifyPair>>> topLevelSets, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { * Computes the cartesian product of topLevelSets step by step.
//ArrayList<Set<Set<UnifyPair>>> remainingSets = new ArrayList<>(topLevelSets); * @param topLevelSets List of Sets of Sets, where a cartesian product have to be built
* Ex.: [{{a =. Integer}, {a = Object}}, {{a = Vector<b>, b =. Integer}, {a = Vector<b>, b =. Object}}]
* @param eq Original set of equations which should be unified
* @param oderConstraints Remaining or-constraints
* @param fc The finite closure
* @param parallel If the algorithm should be parallelized run
* @param rekTiefe Deep of recursive calls
* @return The set of all principal type unifiers
*/
Set<Set<UnifyPair>> computeCartesianRecursive(ArrayList<Set<? extends Set<UnifyPair>>> topLevelSets, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) {
fstElems.addAll(topLevelSets.stream() //oneElems: Alle 1-elementigen Mengen, die nur ein Paar
//a <. theta, theta <. a oder a =. theta enthalten
Set<Set<UnifyPair>> oneElems = new HashSet<>();
oneElems.addAll(topLevelSets.stream()
.filter(x -> x.size()==1) .filter(x -> x.size()==1)
.map(y -> y.stream().findFirst().get()) .map(y -> y.stream().findFirst().get())
.collect(Collectors.toCollection(HashSet::new))); .collect(Collectors.toCollection(HashSet::new)));
ArrayList<Set<? extends Set<UnifyPair>>> remainingSets = topLevelSets.stream()
.filter(x -> x.size()>1) //optNextSet: Eine mehrelementige Menge, wenn vorhanden
.collect(Collectors.toCollection(ArrayList::new)); Optional<Set<? extends Set<UnifyPair>>> optNextSet = topLevelSets.stream().filter(x -> x.size()>1).findAny();
if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig
Set<Set<UnifyPair>> result = unify2(fstElems, eq, oderConstraints, fc, parallel, rekTiefe, finalresult); if (!optNextSet.isPresent()) {//Alle Elemente sind 1-elementig
Set<Set<UnifyPair>> result = unify2(oneElems, eq, oderConstraints, fc, parallel, rekTiefe);
return result; return result;
} }
Set<? extends Set<UnifyPair>> nextSet = remainingSets.remove(0);
Set<? extends Set<UnifyPair>> nextSet = optNextSet.get();
//writeLog("nextSet: " + nextSet.toString()); //writeLog("nextSet: " + nextSet.toString());
List<Set<UnifyPair>> nextSetasList =new ArrayList<>(nextSet); List<Set<UnifyPair>> nextSetasList =new ArrayList<>(nextSet);
/* /*
@@ -617,6 +658,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<Set<UnifyPair>> result = new HashSet<>(); Set<Set<UnifyPair>> result = new HashSet<>();
int variance = 0; int variance = 0;
/* Varianzbestimmung Anfang
* Oderconstraint, wenn entweder kein Basepair oder unterschiedliche Basepairs => oderConstraint = true;
* Varianz = 1 => Argumentvariable
* Varianz = -1 => Rückgabevariable
* Varianz = 0 => unklar
* Varianz = 2 => Operatoren oderConstraints */
ArrayList<UnifyPair> zeroNextElem = new ArrayList<>(nextSetasList.get(0)); ArrayList<UnifyPair> zeroNextElem = new ArrayList<>(nextSetasList.get(0));
UnifyPair fstBasePair = zeroNextElem.remove(0).getBasePair(); UnifyPair fstBasePair = zeroNextElem.remove(0).getBasePair();
Boolean oderConstraint = false; Boolean oderConstraint = false;
@@ -639,16 +686,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
} }
else { else {
//variance = 2;
oderConstraint = true; oderConstraint = true;
} }
} }
else { else {
//variance = 2;
oderConstraint = true; oderConstraint = true;
} }
if (oderConstraint) {//Varianz-Bestimmung Oder-Constraints //Varianz-Bestimmung Oder-Constraints
if (oderConstraint) {
if (printtag) System.out.println("nextSetasList " + nextSetasList); if (printtag) System.out.println("nextSetasList " + nextSetasList);
Optional<Integer> optVariance = Optional<Integer> optVariance =
nextSetasList.iterator() nextSetasList.iterator()
@@ -661,23 +707,22 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
((PlaceholderType)x.getGroundBasePair().getLhsType()).getVariance()) ((PlaceholderType)x.getGroundBasePair().getLhsType()).getVariance())
.findAny(); .findAny();
//Fuer Operatorenaufrufe wird variance auf 2 gesetzt. //Fuer Operatorenaufrufe wird variance auf 2 gesetzt.
//da kein Receiver existiert also keon x.getGroundBasePair().getLhsType() instanceof PlaceholderType //da kein Receiver existiert also kein x.getGroundBasePair().getLhsType() instanceof PlaceholderType
//Es werden alle Elemente des Kartesischen Produkts abgearbeitet //Bei Varianz = 2 werden alle Elemente des Kartesischen Produkts abgearbeitet
variance = optVariance.isPresent() ? optVariance.get() : 2; variance = optVariance.isPresent() ? optVariance.get() : 2;
} }
/* Varianzbestimmung Ende */
if (!nextSetasList.iterator().hasNext())
System.out.print("");
if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1)
System.out.print("");
//writeLog("nextSetasList: " + nextSetasList.toString()); //writeLog("nextSetasList: " + nextSetasList.toString());
Set<UnifyPair> nextSetElem = nextSetasList.get(0); Set<UnifyPair> nextSetElem = nextSetasList.get(0);
//writeLog("BasePair1: " + nextSetElem + " " + nextSetElem.iterator().next().getBasePair()); //writeLog("BasePair1: " + nextSetElem + " " + nextSetElem.iterator().next().getBasePair());
/* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet alle Paare a < ty1 oder ty2 < a aus fstElems */ /* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet
* alle Paare a < ty1 oder ty2 < a aus oneElems */
Set<UnifyPair> sameEqSet = new HashSet<>(); Set<UnifyPair> sameEqSet = new HashSet<>();
//optOrigPair enthaelt ggf. das Paar a = ty \in nextSet
Optional<UnifyPair> optOrigPair = null; Optional<UnifyPair> optOrigPair = null;
//if (variance != 2) {
if (!oderConstraint) { if (!oderConstraint) {
optOrigPair = nextSetElem.stream().filter(x -> ( optOrigPair = nextSetElem.stream().filter(x -> (
//x.getBasePair() != null && ist gegeben wenn variance != 2 //x.getBasePair() != null && ist gegeben wenn variance != 2
@@ -701,7 +746,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
tyVar = origPair.getRhsType(); tyVar = origPair.getRhsType();
} }
UnifyType tyVarEF = tyVar; UnifyType tyVarEF = tyVar;
sameEqSet = fstElems.stream().map(xx -> xx.iterator().next()) sameEqSet = oneElems.stream().map(xx -> xx.iterator().next())
.filter(x -> (((x.getLhsType().equals(tyVarEF) && !(x.getRhsType() instanceof PlaceholderType)) .filter(x -> (((x.getLhsType().equals(tyVarEF) && !(x.getRhsType() instanceof PlaceholderType))
|| (x.getRhsType().equals(tyVarEF) && !(x.getLhsType() instanceof PlaceholderType))))) || (x.getRhsType().equals(tyVarEF) && !(x.getLhsType() instanceof PlaceholderType)))))
.collect(Collectors.toCollection(HashSet::new)); .collect(Collectors.toCollection(HashSet::new));
@@ -710,14 +755,21 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
/* sameEqSet-Bestimmung Ende */ /* sameEqSet-Bestimmung Ende */
Set<UnifyPair> a = null; Set<UnifyPair> a = null;
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { while (nextSetasList.size() > 0) {
Set<UnifyPair> a_last = a; Set<UnifyPair> a_last = a;
//Liste der Faelle für die parallele Verarbeitung /* Liste der Faelle für die parallele Verarbeitung
* Enthaelt Elemente, die nicht in Relation zu aktuellem Fall in der
* Variablen a stehen. Diese muesse auf alle Faelle bearbeitet werden,
* Deshalb wird ihre Berechnung parallel angestossen.
*/
List<Set<UnifyPair>> nextSetasListRest = new ArrayList<>(); List<Set<UnifyPair>> nextSetasListRest = new ArrayList<>();
//Liste der Faelle, bei dem Receiver jeweils "? extends" enthaelt bzw. nicht enthaelt /* Liste der Faelle, bei dem Receiver jeweils "? extends" enthaelt bzw. nicht enthaelt
//In der Regel ein Element * In der Regel ist dies genau ein Element
* Dieses Element wird später aus nextSetasList geloescht, wenn das jeweils andere Element zum Erfolg
* gefuehrt hat.
*/
List<Set<UnifyPair>> nextSetasListOderConstraints = new ArrayList<>(); List<Set<UnifyPair>> nextSetasListOderConstraints = new ArrayList<>();
writeLog("nextSet: " + nextSet.toString()); writeLog("nextSet: " + nextSet.toString());
@@ -740,6 +792,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
//Alle maximale Elemente in nextSetasListRest bestimmen //Alle maximale Elemente in nextSetasListRest bestimmen
//nur für diese wird parallele Berechnung angestossen.
nextSetasListRest = oup.maxElements(nextSetasListRest); nextSetasListRest = oup.maxElements(nextSetasListRest);
} }
else if (variance == -1) { else if (variance == -1) {
@@ -760,10 +813,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
} }
//Alle minimalen Elemente in nextSetasListRest bestimmen //Alle minimalen Elemente in nextSetasListRest bestimmen
//nur für diese wird parallele Berechnung angestossen.
nextSetasListRest = oup.minElements(nextSetasListRest); nextSetasListRest = oup.minElements(nextSetasListRest);
} }
else if (variance == 2) { else if (variance == 2) {
a = nextSetasList.remove(0); a = nextSetasList.remove(0);
//Fuer alle Elemente wird parallele Berechnung angestossen.
nextSetasListRest = new ArrayList<>(nextSetasList); nextSetasListRest = new ArrayList<>(nextSetasList);
} }
else if (variance == 0) { else if (variance == 0) {
@@ -789,54 +845,32 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
} }
} }
//writeLog("nextSet: " + nextSetasList.toString()+ "\n");
//nextSetasList.remove(a);
//PL 2018-03-01
//TODO: 1. Maximum und Minimum unterscheiden
//TODO: 2. compare noch für alle Elmemente die nicht X =. ty sind erweitern
//for(Set<UnifyPair> a : newSet) {
i++; i++;
Set<Set<UnifyPair>> elems = new HashSet<Set<UnifyPair>>(fstElems); Set<Set<UnifyPair>> elems = new HashSet<Set<UnifyPair>>(oneElems);
writeLog("a1: " + rekTiefe + " "+ "variance: "+ variance + " " + a.toString()+ "\n"); writeLog("a1: " + rekTiefe + " "+ "variance: "+ variance + " " + a.toString()+ "\n");
//elems.add(a); PL 2019-01-20 Muss weg, weil das in jeweiligen Thread erfolgen muss. Fuer den sequentiellen Fall
//im else-Zweig //Ergebnisvariable für den aktuelle Thread
//if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt
//writeLog("Vor unify2 Aufruf: " + elems.toString());
Set<Set<UnifyPair>> res = new HashSet<>(); Set<Set<UnifyPair>> res = new HashSet<>();
//Menge der Ergebnisse der geforkten Threads
Set<Set<Set<UnifyPair>>> add_res = new HashSet<>(); Set<Set<Set<UnifyPair>>> add_res = new HashSet<>();
Set<Set<UnifyPair>> aParDef = new HashSet<>(); Set<Set<UnifyPair>> aParDef = new HashSet<>();
/* PL 2019-03-11 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ /* Wenn bei (a \in theta) \in a zu Widerspruch in oneElems wird
if (!oderConstraint && !sameEqSet.isEmpty()) { * a verworfen und zu nächstem Element von nextSetasList gegangen
Optional<UnifyPair> optAPair = a.stream().filter(x -> ( */
//x.getBasePair() != null && ist gegeben wenn variance != 2 if (!oderConstraint && !sameEqSet.isEmpty() && !checkNoContradiction(a, sameEqSet, result)) {
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && a = null;
(x.getPairOp().equals(PairOperator.EQUALSDOT) noShortendElements++;
/* continue;
(x.getBasePair().getLhsType() instanceof PlaceholderType
&& x.getLhsType().equals(x.getBasePair().getLhsType()))
|| (x.getBasePair().getRhsType() instanceof PlaceholderType
&& x.getLhsType().equals(x.getBasePair().getRhsType())
*/
))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist
x.getLhsType().equals(x.getBasePair().getLhsType()) ||
x.getLhsType().equals(x.getBasePair().getRhsType())
).findFirst();
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
UnifyPair aPair = optAPair.get();
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet);
if (!checkA(aPair, sameEqSet, elems, result)) {
a = null;
noShortendElements++;
continue;
}
}
} }
/* PL 2019-03-11 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
/* Wenn parallel gearbeitet wird, wird je nach Varianz ein neuer Thread
* gestartet, der parallel weiterarbeitet.
*/
if(parallel && (variance == 1) && noOfThread <= MaxNoOfThreads) { if(parallel && (variance == 1) && noOfThread <= MaxNoOfThreads) {
Set<TypeUnify2Task> forks = new HashSet<>(); Set<TypeUnify2Task> forks = new HashSet<>();
Set<UnifyPair> newEqOrig = new HashSet<>(eq); Set<UnifyPair> newEqOrig = new HashSet<>(eq);
@@ -865,35 +899,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
writeLog("1 RM" + nSaL.toString()); writeLog("1 RM" + nSaL.toString());
} }
/* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ if (!oderConstraint) {
if (!oderConstraint) {//weiss nicht ob das wirklich stimmt //ueberpruefung ob zu a =. ty \in nSaL in sameEqSet ein Widerspruch besteht
Optional<UnifyPair> optAPair = nSaL.stream().filter(x -> ( if (!sameEqSet.isEmpty() && !checkNoContradiction(nSaL, sameEqSet, result)) {
//x.getBasePair() != null && ist gegeben wenn variance != 2 nSaL = null;
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && noShortendElements++;
(x.getPairOp().equals(PairOperator.EQUALSDOT) continue;
/*
(x.getBasePair().getLhsType() instanceof PlaceholderType
&& x.getLhsType().equals(x.getBasePair().getLhsType()))
|| (x.getBasePair().getRhsType() instanceof PlaceholderType
&& x.getLhsType().equals(x.getBasePair().getRhsType())
*/
))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist
x.getLhsType().equals(x.getBasePair().getLhsType()) ||
x.getLhsType().equals(x.getBasePair().getRhsType())
).findFirst();
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
UnifyPair aPair = optAPair.get();
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet);
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
nSaL = null;
noShortendElements++;
continue;
}
} }
} }
/* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
else { else {
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint()); nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint());
} }
@@ -985,35 +998,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
writeLog("-1 RM" + nSaL.toString()); writeLog("-1 RM" + nSaL.toString());
} }
if (!oderConstraint) {//weiss nicht ob das wirklich stimmt if (!oderConstraint) {
/* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ //ueberpruefung ob zu a =. ty \in nSaL in sameEqSet ein Widerspruch besteht
Optional<UnifyPair> optAPair = nSaL.stream().filter(x -> ( if (!sameEqSet.isEmpty() && !checkNoContradiction(nSaL, sameEqSet, result)) {
//x.getBasePair() != null && ist gegeben wenn variance != 2 nSaL = null;
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && noShortendElements++;
(x.getPairOp().equals(PairOperator.EQUALSDOT) continue;
/*
(x.getBasePair().getLhsType() instanceof PlaceholderType
&& x.getLhsType().equals(x.getBasePair().getLhsType()))
|| (x.getBasePair().getRhsType() instanceof PlaceholderType
&& x.getLhsType().equals(x.getBasePair().getRhsType())
*/
))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist
x.getLhsType().equals(x.getBasePair().getLhsType()) ||
x.getLhsType().equals(x.getBasePair().getRhsType())
).findFirst();
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
UnifyPair aPair = optAPair.get();
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet);
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
nSaL = null;
noShortendElements++;
continue;
}
} }
} }
/* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
else { else {
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint()); nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint());
} }
@@ -1156,11 +1148,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
}; };
} }
//noOfThread++; //noOfThread++;
} else { } else {//parallel = false oder MaxNoOfThreads ist erreicht, sequentiell weiterarbeiten
//parallel = false; //Wenn MaxNoOfThreads erreicht ist, sequentiell weiterarbeiten
elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859 elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859
res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe, finalresult); res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe);
}}} }}}
//Ab hier alle parallele Berechnungen wieder zusammengeführt.
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
result = res; result = res;
@@ -1247,7 +1240,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
else { else {
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
writeLog("RES Fst: reuslt: " + result.toString() + " res: " + res.toString()); writeLog("RES Fst: result: " + result.toString() + " res: " + res.toString());
result.addAll(res); result.addAll(res);
} }
} }
@@ -1259,10 +1252,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//} //}
} }
//}
//else {//duerfte gar nicht mehr vorkommen PL 2018-04-03
//result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel));
//}
if (parallel) { if (parallel) {
for (Set<Set<UnifyPair>> par_res : add_res) { for (Set<Set<UnifyPair>> par_res : add_res) {
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
@@ -1304,6 +1293,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<UnifyPair> a_new = aParDefIt.next(); Set<UnifyPair> a_new = aParDefIt.next();
List<Set<UnifyPair>> smallerSetasList = oup.smallerThan(a_new, nextSetasList); List<Set<UnifyPair>> smallerSetasList = oup.smallerThan(a_new, nextSetasList);
List<Set<UnifyPair>> notInherited = smallerSetasList.stream() List<Set<UnifyPair>> notInherited = smallerSetasList.stream()
.filter(x -> !((Constraint<UnifyPair>)x).isInherited())
.collect(Collectors.toCollection(ArrayList::new)); .collect(Collectors.toCollection(ArrayList::new));
List<Set<UnifyPair>> notErased = new ArrayList<>(); List<Set<UnifyPair>> notErased = new ArrayList<>();
notInherited.stream().forEach(x -> { notErased.addAll(oup.smallerEqThan(x, smallerSetasList)); }); notInherited.stream().forEach(x -> { notErased.addAll(oup.smallerEqThan(x, smallerSetasList)); });
@@ -1345,10 +1335,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
List<Set<UnifyPair>> greaterSetasList = oup.greaterThan(a_new, nextSetasList); List<Set<UnifyPair>> greaterSetasList = oup.greaterThan(a_new, nextSetasList);
//a_new muss hingefuegt werden, wenn es nicht vererbt ist, dann wird es spaeter wieder geloescht //a_new muss hingefuegt werden, wenn es nicht vererbt ist, dann wird es spaeter wieder geloescht
if (!((Constraint<UnifyPair>)a_new).isInherited()) {
greaterSetasList.add(a_new); greaterSetasList.add(a_new);
}
List<Set<UnifyPair>> notInherited = greaterSetasList.stream() List<Set<UnifyPair>> notInherited = greaterSetasList.stream()
.filter(x -> !((Constraint<UnifyPair>)x).isInherited())
.collect(Collectors.toCollection(ArrayList::new)); .collect(Collectors.toCollection(ArrayList::new));
List<Set<UnifyPair>> notErased = new ArrayList<>(); List<Set<UnifyPair>> notErased = new ArrayList<>();
@@ -1399,6 +1390,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
writeLog("Removed: " + nextSetasListOderConstraints); writeLog("Removed: " + nextSetasListOderConstraints);
List<Set<UnifyPair>> smallerSetasList = oup.smallerThan(a, nextSetasList); List<Set<UnifyPair>> smallerSetasList = oup.smallerThan(a, nextSetasList);
List<Set<UnifyPair>> notInherited = smallerSetasList.stream() List<Set<UnifyPair>> notInherited = smallerSetasList.stream()
.filter(x -> !((Constraint<UnifyPair>)x).isInherited())
.collect(Collectors.toCollection(ArrayList::new)); .collect(Collectors.toCollection(ArrayList::new));
List<Set<UnifyPair>> notErased = new ArrayList<>(); List<Set<UnifyPair>> notErased = new ArrayList<>();
notInherited.stream().forEach(x -> { notErased.addAll(oup.smallerEqThan(x, smallerSetasList)); }); notInherited.stream().forEach(x -> { notErased.addAll(oup.smallerEqThan(x, smallerSetasList)); });
@@ -1496,7 +1488,29 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
return result; return result;
} }
protected Boolean checkA (UnifyPair aPair, Set<UnifyPair> sameEqSet, Set<Set<UnifyPair>> elems, Set<Set<UnifyPair>> result) { /**
* checks if there is for (a = ty) \in a in sameEqSet a constradiction
* @param a Set of actual element of constraints with a =. ty \in a
* @param sameEqSet Set of constraints where a <. ty' and ty' <. a
* @param result set of results which contains correct solution s and the
* the error constraints. Error constraints are added
* @result contradiction of (a = ty) in sameEqSet
*/
protected Boolean checkNoContradiction(Set<UnifyPair> a, Set<UnifyPair> sameEqSet, Set<Set<UnifyPair>> result) {
//optAPair enthaelt ggf. das Paar a = ty' \in a
//unterscheidet sich von optOrigPair, da dort a = ty
Optional<UnifyPair> optAPair =
a.stream().filter(x -> (x.getPairOp().equals(PairOperator.EQUALSDOT)))
.filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist
x.getLhsType().equals(x.getBasePair().getLhsType()) ||
x.getLhsType().equals(x.getBasePair().getRhsType()))
.findFirst();
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
UnifyPair aPair = optAPair.get();
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
writeLog("checkA: " + aPair + "sameEqSet: " + sameEqSet); writeLog("checkA: " + aPair + "sameEqSet: " + sameEqSet);
for (UnifyPair sameEq : sameEqSet) { for (UnifyPair sameEq : sameEqSet) {
if (sameEq.getLhsType() instanceof PlaceholderType) { if (sameEq.getLhsType() instanceof PlaceholderType) {
@@ -1506,12 +1520,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
unitedSubst.addAll(sameEq.getAllSubstitutions()); unitedSubst.addAll(sameEq.getAllSubstitutions());
unitedSubst.addAll(sameEq.getAllBases()); unitedSubst.addAll(sameEq.getAllBases());
localEq.add(new UnifyPair(aPair.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); localEq.add(new UnifyPair(aPair.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null));
Set<Set<UnifyPair>> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); finalresult = false;
Set<Set<UnifyPair>> localRes = unify(localEq, new ArrayList<>(), fc, false, 0);
finalresult = true;
if (isUndefinedPairSetSet(localRes)) { if (isUndefinedPairSetSet(localRes)) {
if (result.isEmpty() || isUndefinedPairSetSet(result)) { if (result.isEmpty() || isUndefinedPairSetSet(result)) {
result.addAll(localRes); result.addAll(localRes);
} }
//writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet);
return false; return false;
} }
} }
@@ -1522,20 +1538,25 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
unitedSubst.addAll(sameEq.getAllSubstitutions()); unitedSubst.addAll(sameEq.getAllSubstitutions());
unitedSubst.addAll(sameEq.getAllBases()); unitedSubst.addAll(sameEq.getAllBases());
localEq.add(new UnifyPair(sameEq.getLhsType(), aPair.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); localEq.add(new UnifyPair(sameEq.getLhsType(), aPair.getRhsType(), sameEq.getPairOp(), unitedSubst, null));
Set<Set<UnifyPair>> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); finalresult = false;
Set<Set<UnifyPair>> localRes = unify(localEq, new ArrayList<>(), fc, false, 0);
finalresult = true;
if (isUndefinedPairSetSet(localRes)) { if (isUndefinedPairSetSet(localRes)) {
if (result.isEmpty() || isUndefinedPairSetSet(result)) { if (result.isEmpty() || isUndefinedPairSetSet(result)) {
result.addAll(localRes); result.addAll(localRes);
} }
//writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet);
return false; return false;
} }
} }
} }
//writeLog("TRUE: " + aPair + "sameEqSet: " + sameEqSet); writeLog("TRUE: " + aPair + "sameEqSet: " + sameEqSet);
return true;
}
return true; return true;
} }
protected boolean couldBecorrect(Set<Pair<Set<UnifyPair>, UnifyPair>> reducedUndefResSubstGroundedBasePair, Set<UnifyPair> nextElem) { protected boolean couldBecorrect(Set<Pair<Set<UnifyPair>, UnifyPair>> reducedUndefResSubstGroundedBasePair, Set<UnifyPair> nextElem) {
return reducedUndefResSubstGroundedBasePair.stream() return reducedUndefResSubstGroundedBasePair.stream()
.map(pair -> { .map(pair -> {
@@ -2163,6 +2184,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<Set<UnifyPair>> result = new HashSet<>(); Set<Set<UnifyPair>> result = new HashSet<>();
if (thetaPrime instanceof ReferenceType && ((ReferenceType)thetaPrime).isGenTypeVar()) {
Set<UnifyPair> resultOne = new HashSet<>();
resultOne.add(new UnifyPair (a, thetaPrime, PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
result.add(resultOne);
}
boolean allGen = thetaPrime.getTypeParams().size() > 0; boolean allGen = thetaPrime.getTypeParams().size() > 0;
for(UnifyType t : thetaPrime.getTypeParams()) for(UnifyType t : thetaPrime.getTypeParams())
if(!(t instanceof PlaceholderType) || !((PlaceholderType) t).isGenerated()) { if(!(t instanceof PlaceholderType) || !((PlaceholderType) t).isGenerated()) {
@@ -2502,7 +2529,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
void writeLog(String str) { void writeLog(String str) {
synchronized ( this ) { synchronized ( this ) {
if (log) { if (log && finalresult) {
try { try {
logFile.write("Thread no.:" + thNo + "\n"); logFile.write("Thread no.:" + thNo + "\n");
logFile.write("noOfThread:" + noOfThread + "\n"); logFile.write("noOfThread:" + noOfThread + "\n");

View File

@@ -1,108 +0,0 @@
package de.dhbwstuttgart.unify2;
import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
import de.dhbwstuttgart.typeinference.unify.model.*;
import java.util.*;
import java.util.stream.Collectors;
/**
* Implementation of the Martelli-Montanari unification algorithm.
* @author Florian Steurer
*/
public class MartelliMontanariUnify {
/**
* Finds the most general unifier sigma of the set {t1 =. t1',...,tn =. tn'} so that
* sigma(t1) = sigma(t1') , ... sigma(tn) = sigma(tn').
* @param terms The set of terms to be unified
* @return An optional of the most general unifier if it exists or an empty optional if there is no unifier.
*/
public static Optional<Unifier> unify(UnifyType... terms) {
return unify(Arrays.stream(terms).collect(Collectors.toSet()));
}
public static Optional<Unifier> unify(Set<UnifyType> terms) {
// Sets with less than 2 terms are trivially unified
if(terms.size() < 2)
return Optional.of(Unifier.identity());
// For the the set of terms {t1,...,tn},
// build a list of equations {(t1 = t2), (t2 = t3), (t3 = t4), ....}
ArrayList<UnifyPair> termsList = new ArrayList<UnifyPair>();
Iterator<UnifyType> iter = terms.iterator();
UnifyType prev = iter.next();
while(iter.hasNext()) {
UnifyType next = iter.next();
termsList.add(new UnifyPair(prev, next, PairOperator.EQUALSDOT));
prev = next;
}
// Start with the identity unifier. Substitutions will be added later.
Unifier mgu = Unifier.identity();
// Apply rules while possible
int idx = 0;
while(idx < termsList.size()) {
UnifyPair pair = termsList.get(idx);
UnifyType rhsType = pair.getRhsType();
UnifyType lhsType = pair.getLhsType();
TypeParams rhsTypeParams = rhsType.getTypeParams();
TypeParams lhsTypeParams = lhsType.getTypeParams();
// REDUCE - Rule
if(!(rhsType instanceof PlaceholderType) && !(lhsType instanceof PlaceholderType)) {
Set<UnifyPair> result = new HashSet<>();
// f<...> = g<...> with f != g are not unifiable
if(!rhsType.getName().equals(lhsType.getName()))
return Optional.empty(); // conflict
// f<t1,...,tn> = f<s1,...,sm> are not unifiable
if(rhsTypeParams.size() != lhsTypeParams.size())
return Optional.empty(); // conflict
// f = g is not unifiable (cannot be f = f because erase rule would have been applied)
//if(rhsTypeParams.size() == 0)
//return Optional.empty();
// Unpack the arguments
for(int i = 0; i < rhsTypeParams.size(); i++)
result.add(new UnifyPair(rhsTypeParams.get(i), lhsTypeParams.get(i), PairOperator.EQUALSDOT));
termsList.remove(idx);
termsList.addAll(result);
continue;
}
// DELETE - Rule
if(pair.getRhsType().equals(pair.getLhsType())) {
termsList.remove(idx);
continue;
}
// SWAP - Rule
if(!(lhsType instanceof PlaceholderType) && (rhsType instanceof PlaceholderType)) {
termsList.remove(idx);
termsList.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT));
continue;
}
// OCCURS-CHECK
if(pair.getLhsType() instanceof PlaceholderType
&& pair.getRhsType().getTypeParams().occurs((PlaceholderType) pair.getLhsType()))
return Optional.empty();
// SUBST - Rule
if(lhsType instanceof PlaceholderType) {
mgu.add((PlaceholderType) lhsType, rhsType);
//PL 2018-04-01 nach checken, ob es richtig ist, dass keine Substitutionen uebergeben werden muessen.
termsList = termsList.stream().map(x -> mgu.apply(x)).collect(Collectors.toCollection(ArrayList::new));
idx = idx+1 == termsList.size() ? 0 : idx+1;
continue;
}
idx++;
}
return Optional.of(mgu);
}
}

View File

@@ -1,922 +0,0 @@
package de.dhbwstuttgart.unify2;
import de.dhbwstuttgart.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet;
import de.dhbwstuttgart.typeinference.unify.model.*;
import org.antlr.v4.tool.Rule;
import org.apache.commons.io.output.NullOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* Implementation of the type inference rules.
* @author Florian Steurer
*
*/
public class RuleSet {
/**
* Repeatedly applies type unification rules to a set of equations.
* This is step one of the unification algorithm.
* @return The set of pairs that results from repeated application of the inference rules.
*/
public static Set<UnifyPair> applyTypeUnificationRules(Set<UnifyPair> eq, IFiniteClosure fc) {
/*
* Rule Application Strategy:
*
* 1. Swap all pairs and erase all erasable pairs
* 2. Apply all possible rules to a single pair, then move it to the result set.
* Iterating over pairs first, then iterating over rules prevents the application
* of rules to a "finished" pair over and over.
* 2.1 Apply all rules repeatedly except for erase rules. If
* the application of a rule creates new pairs, check immediately
* against the erase rules.
*/
LinkedHashSet<UnifyPair> targetSet = new LinkedHashSet<UnifyPair>();
LinkedList<UnifyPair> eqQueue = new LinkedList<>();
/*
* Swap all pairs and erase all erasable pairs
*/
eq.forEach(x -> swapAddOrErase(x, fc, eqQueue));
/*
* Apply rules until the queue is empty
*/
while(!eqQueue.isEmpty()) {
UnifyPair pair = eqQueue.pollFirst();
// ReduceUp, ReduceLow, ReduceUpLow
Optional<UnifyPair> opt = RuleSet.reduceUpLow(pair);
opt = opt.isPresent() ? opt : RuleSet.reduceLow(pair);
opt = opt.isPresent() ? opt : RuleSet.reduceUp(pair);
opt = opt.isPresent() ? opt : RuleSet.reduceWildcardLow(pair);
opt = opt.isPresent() ? opt : RuleSet.reduceWildcardLowRight(pair);
opt = opt.isPresent() ? opt : RuleSet.reduceWildcardUp(pair);
opt = opt.isPresent() ? opt : RuleSet.reduceWildcardUpRight(pair);
//PL 2018-03-06 auskommentiert muesste falsch sein vgl. JAVA_BSP/Wildcard6.java
//opt = opt.isPresent() ? opt : rules.reduceWildcardLowUp(pair);
//opt = opt.isPresent() ? opt : rules.reduceWildcardUpLow(pair);
//opt = opt.isPresent() ? opt : rules.reduceWildcardLeft(pair);
// Reduce TPH
opt = opt.isPresent() ? opt : RuleSet.reduceTph(pair);
// One of the rules has been applied
if(opt.isPresent()) {
swapAddOrErase(opt.get(), fc, eqQueue);
continue;
}
// Reduce1, Reduce2, ReduceExt, ReduceSup, ReduceEq
//try {
// logFile.write("PAIR1 " + pair + "\n");
// logFile.flush();
//}
//catch (IOException e) { }
Optional<Set<UnifyPair>> optSet = RuleSet.reduce1(pair, fc);
optSet = optSet.isPresent() ? optSet : RuleSet.reduce2(pair);
optSet = optSet.isPresent() ? optSet : RuleSet.reduceExt(pair, fc);
optSet = optSet.isPresent() ? optSet : RuleSet.reduceSup(pair, fc);
optSet = optSet.isPresent() ? optSet : RuleSet.reduceEq(pair);
// ReduceTphExt, ReduceTphSup
optSet = optSet.isPresent() ? optSet : RuleSet.reduceTphExt(pair);
optSet = optSet.isPresent() ? optSet : RuleSet.reduceTphSup(pair);
// FunN Rules
optSet = optSet.isPresent() ? optSet : RuleSet.reduceFunN(pair);
optSet = optSet.isPresent() ? optSet : RuleSet.greaterFunN(pair);
optSet = optSet.isPresent() ? optSet : RuleSet.smallerFunN(pair);
// One of the rules has been applied
if(optSet.isPresent()) {
optSet.get().forEach(x -> swapAddOrErase(x, fc, eqQueue));
continue;
}
// Adapt, AdaptExt, AdaptSup
//try {
// logFile.write("PAIR2 " + pair + "\n");
// logFile.flush();
//}
//catch (IOException e) { }
opt = RuleSet.adapt(pair, fc);
opt = opt.isPresent() ? opt : RuleSet.adaptExt(pair, fc);
opt = opt.isPresent() ? opt : RuleSet.adaptSup(pair, fc);
// One of the rules has been applied
if(opt.isPresent()) {
swapAddOrErase(opt.get(), fc, eqQueue);
continue;
}
// None of the rules has been applied
targetSet.add(pair);
}
return targetSet;
}
/**
* Applies the rule swap to a pair if possible. Then adds the pair to the set if no erase rule applies.
* If an erase rule applies, the pair is not added (erased).
* @param pair The pair to swap and add or erase.
* @param collection The collection to which the pairs are added.
*/
static void swapAddOrErase(UnifyPair pair, IFiniteClosure fc, Collection<UnifyPair> collection) {
Optional<UnifyPair> opt = RuleSet.swap(pair);
UnifyPair pair2 = opt.isPresent() ? opt.get() : pair;
if(RuleSet.erase1(pair2, fc) || RuleSet.erase3(pair2) || RuleSet.erase2(pair2, fc))
return;
collection.add(pair2);
}
static Optional<UnifyPair> reduceUp(UnifyPair pair) {
// Check if reduce up is applicable
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
UnifyType rhsType = pair.getRhsType();
if(!(rhsType instanceof SuperType))
return Optional.empty();
UnifyType lhsType = pair.getLhsType();
if(!(lhsType instanceof ReferenceType) && !(lhsType instanceof PlaceholderType))
return Optional.empty();
// Rule is applicable, unpack the SuperType
return Optional.of(new UnifyPair(lhsType, ((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
}
static Optional<UnifyPair> reduceLow(UnifyPair pair) {
// Check if rule is applicable
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
UnifyType lhsType = pair.getLhsType();
if(!(lhsType instanceof ExtendsType))
return Optional.empty();
UnifyType rhsType = pair.getRhsType();
if(!(rhsType instanceof ReferenceType) && !(rhsType instanceof PlaceholderType))
return Optional.empty();
// Rule is applicable, unpack the ExtendsType
return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), rhsType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
}
static Optional<UnifyPair> reduceUpLow(UnifyPair pair) {
// Check if rule is applicable
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
UnifyType lhsType = pair.getLhsType();
if(!(lhsType instanceof ExtendsType))
return Optional.empty();
UnifyType rhsType = pair.getRhsType();
if(!(rhsType instanceof SuperType))
return Optional.empty();
// Rule is applicable, unpack both sides
return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(),((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
}
static Optional<Set<UnifyPair>> reduceExt(UnifyPair pair, IFiniteClosure fc) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
UnifyType x = pair.getLhsType();
UnifyType sTypeX;
if(x instanceof ReferenceType)
sTypeX = x;
else if(x instanceof ExtendsType)
sTypeX = ((ExtendsType) x).getExtendedType();
else
return Optional.empty();
UnifyType extY = pair.getRhsType();
if(!(extY instanceof ExtendsType))
return Optional.empty();
if(x.getTypeParams().empty() || extY.getTypeParams().size() != x.getTypeParams().size())
return Optional.empty();
UnifyType xFromFc = fc.getLeftHandedType(sTypeX.getName()).orElse(null);
if(xFromFc == null || !xFromFc.getTypeParams().arePlaceholders())
return Optional.empty();
if(x instanceof ExtendsType)
xFromFc = new ExtendsType(xFromFc);
UnifyType extYFromFc = fc.grArg(xFromFc, new HashSet<>()).stream().filter(t -> t.getName().equals(extY.getName())).filter(t -> t.getTypeParams().arePlaceholders()).findAny().orElse(null);
if(extYFromFc == null || extYFromFc.getTypeParams() != xFromFc.getTypeParams())
return Optional.empty();
TypeParams extYParams = extY.getTypeParams();
TypeParams xParams = x.getTypeParams();
int[] pi = pi(xParams, extYParams);
if(pi.length == 0)
return Optional.empty();
Set<UnifyPair> result = new HashSet<>();
for(int rhsIdx = 0; rhsIdx < extYParams.size(); rhsIdx++)
result.add(new UnifyPair(xParams.get(pi[rhsIdx]), extYParams.get(rhsIdx), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
return Optional.of(result);
}
static Optional<Set<UnifyPair>> reduceSup(UnifyPair pair, IFiniteClosure fc) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
UnifyType x = pair.getLhsType();
UnifyType sTypeX;
if(x instanceof ReferenceType)
sTypeX = x;
else if(x instanceof SuperType)
sTypeX = ((SuperType) x).getSuperedType();
else
return Optional.empty();
UnifyType supY = pair.getRhsType();
if(!(supY instanceof SuperType))
return Optional.empty();
if(x.getTypeParams().empty() || supY.getTypeParams().size() != x.getTypeParams().size())
return Optional.empty();
UnifyType xFromFc = fc.getLeftHandedType(sTypeX.getName()).orElse(null);
if(xFromFc == null || !xFromFc.getTypeParams().arePlaceholders())
return Optional.empty();
if(x instanceof SuperType)
xFromFc = new SuperType(xFromFc);
UnifyType supYFromFc = fc.grArg(xFromFc, new HashSet<>()).stream().filter(t -> t.getName().equals(supY.getName())).filter(t -> t.getTypeParams().arePlaceholders()).findAny().orElse(null);
if(supYFromFc == null || supYFromFc.getTypeParams() != xFromFc.getTypeParams())
return Optional.empty();
TypeParams supYParams = supY.getTypeParams();
TypeParams xParams = x.getTypeParams();
Set<UnifyPair> result = new HashSet<>();
int[] pi = pi(xParams, supYParams);
if(pi.length == 0)
return Optional.empty();
for(int rhsIdx = 0; rhsIdx < supYParams.size(); rhsIdx++)
result.add(new UnifyPair(supYParams.get(rhsIdx), xParams.get(pi[rhsIdx]), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
return Optional.of(result);
}
static Optional<Set<UnifyPair>> reduceEq(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
UnifyType lhsType = pair.getLhsType();
if(lhsType instanceof PlaceholderType || lhsType.getTypeParams().empty())
return Optional.empty();
UnifyType rhsType = pair.getRhsType();
if(!rhsType.getName().equals(lhsType.getName()))
return Optional.empty();
if(rhsType instanceof PlaceholderType || lhsType instanceof PlaceholderType || rhsType.getTypeParams().empty())
return Optional.empty();
if(rhsType.getTypeParams().size() != lhsType.getTypeParams().size())
return Optional.empty();
// Keine Permutation wie im Paper nötig
Set<UnifyPair> result = new HashSet<>();
TypeParams lhsTypeParams = lhsType.getTypeParams();
TypeParams rhsTypeParams = rhsType.getTypeParams();
for(int i = 0; i < lhsTypeParams.size(); i++)
result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
return Optional.of(result);
}
static Optional<Set<UnifyPair>> reduce1(UnifyPair pair, IFiniteClosure fc) {
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
UnifyType c = pair.getLhsType();
if(!(c instanceof ReferenceType))
return Optional.empty();
UnifyType d = pair.getRhsType();
if(!(d instanceof ReferenceType))
return Optional.empty();
ReferenceType lhsSType = (ReferenceType) c;
ReferenceType rhsSType = (ReferenceType) d;
//try {
// logFile.write("PAIR Rules: " + pair + "\n");
// logFile.flush();
//}
//catch (IOException e) { }
if(lhsSType.getTypeParams().empty() || lhsSType.getTypeParams().size() != rhsSType.getTypeParams().size())
return Optional.empty();
UnifyType cFromFc = fc.getLeftHandedType(c.getName()).orElse(null);
//2018-02-23: liefert Vector<Vector<Integer>>: Das kann nicht sein.
//NOCHMAL UEBERPRUEFEN
//PL 18-02-09 Eingfuegt Anfang
//C und D koennen auch gleich sein.
if (c.getName().equals(d.getName())) {
Set<UnifyPair> result = new HashSet<>();
TypeParams rhsTypeParams = d.getTypeParams();
TypeParams lhsTypeParams = c.getTypeParams();
for(int rhsIdx = 0; rhsIdx < c.getTypeParams().size(); rhsIdx++)
result.add(new UnifyPair(lhsTypeParams.get(rhsIdx), rhsTypeParams.get(rhsIdx), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
return Optional.of(result);
}
//PL 18-02-09 Eingfuegt ENDE
//try {
// logFile.write("cFromFc: " + cFromFc);
// logFile.flush();
//}
//catch (IOException e) { }
if(cFromFc == null || !cFromFc.getTypeParams().arePlaceholders())
return Optional.empty();
UnifyType dFromFc = fc.getAncestors(cFromFc).stream().filter(x -> x.getName().equals(d.getName())).findAny().orElse(null);
//try {
// logFile.write("cFromFc: " + cFromFc);
// logFile.flush();
//}
//catch (IOException e) { }
if(dFromFc == null || !dFromFc.getTypeParams().arePlaceholders() || dFromFc.getTypeParams().size() != cFromFc.getTypeParams().size())
return Optional.empty();
//System.out.println("cFromFc: " + cFromFc);
//System.out.println("dFromFc: " + dFromFc);
int[] pi = pi(cFromFc.getTypeParams(), dFromFc.getTypeParams());
if(pi.length == 0)
return Optional.empty();
TypeParams rhsTypeParams = d.getTypeParams();
TypeParams lhsTypeParams = c.getTypeParams();
Set<UnifyPair> result = new HashSet<>();
for(int rhsIdx = 0; rhsIdx < rhsTypeParams.size(); rhsIdx++)
result.add(new UnifyPair(lhsTypeParams.get(pi[rhsIdx]), rhsTypeParams.get(rhsIdx), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
return Optional.of(result);
}
static Optional<Set<UnifyPair>> reduce2(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.EQUALSDOT)
return Optional.empty();
UnifyType lhsType = pair.getLhsType();
ReferenceType lhsSType;
UnifyType rhsType = pair.getRhsType();
ReferenceType rhsSType;
if ((lhsType instanceof ReferenceType) && (rhsType instanceof ReferenceType)) {
lhsSType = (ReferenceType) lhsType;
rhsSType = (ReferenceType) rhsType;
}
else if (((lhsType instanceof ExtendsType) && (rhsType instanceof ExtendsType))
|| ((lhsType instanceof SuperType) && (rhsType instanceof SuperType))) {
UnifyType lhsSTypeRaw = ((WildcardType) lhsType).getWildcardedType();
UnifyType rhsSTypeRaw = ((WildcardType) rhsType).getWildcardedType();
if ((lhsSTypeRaw instanceof ReferenceType) && (rhsSTypeRaw instanceof ReferenceType)) {
lhsSType = (ReferenceType) lhsSTypeRaw;
rhsSType = (ReferenceType) rhsSTypeRaw;
}
else
return Optional.empty();
}
else
return Optional.empty();
if(lhsSType.getTypeParams().empty())
return Optional.empty();
if(!rhsSType.getName().equals(lhsSType.getName()))
return Optional.empty();
if(!(lhsSType.getTypeParams().size()==rhsSType.getTypeParams().size()))throw new DebugException("Fehler in Unifizierung"+ " " + lhsSType.toString() + " " + rhsSType.toString());
//if(rhsSType.getTypeParams().size() != lhsSType.getTypeParams().size())
// return Optional.empty();
Set<UnifyPair> result = new HashSet<>();
TypeParams rhsTypeParams = rhsSType.getTypeParams();
TypeParams lhsTypeParams = lhsSType.getTypeParams();
for(int i = 0; i < rhsTypeParams.size(); i++)
result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
return Optional.of(result);
}
static boolean erase1(UnifyPair pair, IFiniteClosure fc) {
if((pair.getPairOp() != PairOperator.SMALLERDOT) && (pair.getPairOp() != PairOperator.SMALLERNEQDOT))
return false;
if (pair.getPairOp() == PairOperator.SMALLERNEQDOT) {
UnifyType lhs = pair.getLhsType();
UnifyType rhs = pair.getRhsType();
if (lhs instanceof WildcardType) {
lhs = ((WildcardType)lhs).getWildcardedType();
}
if (rhs instanceof WildcardType) {
rhs = ((WildcardType)rhs).getWildcardedType();
}
if (lhs.equals(rhs)){
return false;
}
}
UnifyType lhsType = pair.getLhsType();
if(!(lhsType instanceof ReferenceType) && !(lhsType instanceof PlaceholderType))
return false;
UnifyType rhsType = pair.getRhsType();
if(!(rhsType instanceof ReferenceType) && !(rhsType instanceof PlaceholderType))
return false;
return fc.greater(lhsType, new HashSet<>()).contains(rhsType);
}
static boolean erase2(UnifyPair pair, IFiniteClosure fc) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return false;
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
return fc.grArg(lhsType, new HashSet<>()).contains(rhsType);
}
static boolean erase3(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.EQUALSDOT)
return false;
return pair.getLhsType().equals(pair.getRhsType());
}
static Optional<UnifyPair> swap(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.EQUALSDOT)
return Optional.empty();
if(pair.getLhsType() instanceof PlaceholderType)
return Optional.empty();
if(!(pair.getRhsType() instanceof PlaceholderType))
return Optional.empty();
return Optional.of(new UnifyPair(pair.getRhsType(), pair.getLhsType(), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
}
static Optional<UnifyPair> adapt(UnifyPair pair, IFiniteClosure fc) {
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
UnifyType typeD = pair.getLhsType();
if(!(typeD instanceof ReferenceType))
return Optional.empty();
UnifyType typeDs = pair.getRhsType();
if(!(typeDs instanceof ReferenceType))
return Optional.empty();
/*if(typeD.getTypeParams().size() == 0 || typeDs.getTypeParams().size() == 0)
return Optional.empty();*/
if(typeD.getName().equals(typeDs.getName()))
return Optional.empty();
Optional<UnifyType> opt = fc.getLeftHandedType(typeD.getName());
if(!opt.isPresent())
return Optional.empty();
// The generic Version of Type D (D<a1, a2, a3, ... >)
UnifyType typeDgen = opt.get();
// Actually greater+ because the types are ensured to have different names
Set<UnifyType> greater = fc.getAncestors(typeDgen);
opt = greater.stream().filter(x -> x.getName().equals(typeDs.getName())).findAny();
if(!opt.isPresent())
return Optional.empty();
UnifyType newLhs = opt.get();
TypeParams typeDParams = typeD.getTypeParams();
TypeParams typeDgenParams = typeDgen.getTypeParams();
Unifier unif = Unifier.identity();
for(int i = 0; i < typeDParams.size(); i++) {
//System.out.println("ADAPT" +typeDgenParams);
if (typeDgenParams.get(i) instanceof PlaceholderType)
unif.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i));
else System.out.println("ERROR");
}
return Optional.of(new UnifyPair(unif.apply(newLhs), typeDs, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
}
static Optional<UnifyPair> adaptExt(UnifyPair pair, IFiniteClosure fc) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
UnifyType typeD = pair.getLhsType();
if(!(typeD instanceof ReferenceType) && !(typeD instanceof ExtendsType))
return Optional.empty();
UnifyType typeExtDs = pair.getRhsType();
if(!(typeExtDs instanceof ExtendsType))
return Optional.empty();
if(typeD.getTypeParams().size() == 0 || typeExtDs.getTypeParams().size() == 0)
return Optional.empty();
UnifyType typeDgen;
if(typeD instanceof ReferenceType)
typeDgen = fc.getLeftHandedType(typeD.getName()).orElse(null);
else {
Optional<UnifyType> opt = fc.getLeftHandedType(((ExtendsType) typeD).getExtendedType().getName());
typeDgen = opt.isPresent() ? new ExtendsType(opt.get()) : null;
}
if(typeDgen == null)
return Optional.empty();
Set<UnifyType> grArg = fc.grArg(typeDgen, new HashSet<>());
Optional<UnifyType> opt = grArg.stream().filter(x -> x.getName().equals(typeExtDs.getName())).findAny();
if(!opt.isPresent())
return Optional.empty();
UnifyType newLhs = ((ExtendsType) opt.get()).getExtendedType();
TypeParams typeDParams = typeD.getTypeParams();
TypeParams typeDgenParams = typeDgen.getTypeParams();
Unifier unif = new Unifier((PlaceholderType) typeDgenParams.get(0), typeDParams.get(0));
for(int i = 1; i < typeDParams.size(); i++)
unif.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i));
return Optional.of(new UnifyPair(unif.apply(newLhs), typeExtDs, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
}
static Optional<UnifyPair> adaptSup(UnifyPair pair, IFiniteClosure fc) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
UnifyType typeDs = pair.getLhsType();
if(!(typeDs instanceof ReferenceType) && !(typeDs instanceof SuperType))
return Optional.empty();
UnifyType typeSupD = pair.getRhsType();
if(!(typeSupD instanceof SuperType))
return Optional.empty();
if(typeDs.getTypeParams().size() == 0 || typeSupD.getTypeParams().size() == 0)
return Optional.empty();
Optional<UnifyType> opt = fc.getLeftHandedType(((SuperType) typeSupD).getSuperedType().getName());
if(!opt.isPresent())
return Optional.empty();
UnifyType typeDgen = opt.get();
UnifyType typeSupDgen = new SuperType(typeDgen);
// Use of smArg instead of grArg because
// a in grArg(b) => b in smArg(a)
Set<UnifyType> smArg = fc.smArg(typeSupDgen, new HashSet<>());
opt = smArg.stream().filter(x -> x.getName().equals(typeDs.getName())).findAny();
if(!opt.isPresent())
return Optional.empty();
// New RHS
UnifyType newRhs = null;
if(typeDs instanceof ReferenceType)
newRhs = new ExtendsType(typeDs);
else
newRhs = new ExtendsType(((SuperType) typeDs).getSuperedType());
// New LHS
UnifyType newLhs = opt.get();
TypeParams typeDParams = typeSupD.getTypeParams();
TypeParams typeSupDsgenParams = typeSupDgen.getTypeParams();
Unifier unif = new Unifier((PlaceholderType) typeSupDsgenParams.get(0), typeDParams.get(0));
for(int i = 1; i < typeDParams.size(); i++)
unif.add((PlaceholderType) typeSupDsgenParams.get(i), typeDParams.get(i));
return Optional.of(new UnifyPair(unif.apply(newLhs), newRhs, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
}
/**
* Finds the permutation pi of the type arguments of two types based on the finite closure
* @param cArgs The type which arguments are permuted
* @param dArgs The other type
* @return An array containing the values of pi for every type argument of C or an empty array if the search failed.
*/
private static int[] pi(TypeParams cArgs, TypeParams dArgs) {
if(!(cArgs.size()==dArgs.size()))throw new DebugException("Fehler in Unifizierung");
int[] permutation = new int[dArgs.size()];
boolean succ = true;
for (int dArgIdx = 0; dArgIdx < dArgs.size() && succ; dArgIdx++) {
UnifyType dArg = dArgs.get(dArgIdx);
succ = false;
for (int pi = 0; pi < cArgs.size(); pi++)
if (cArgs.get(pi).getName().equals(dArg.getName())) {
permutation[dArgIdx] = pi;
succ = true;
break;
}
}
return succ ? permutation : new int[0];
}
static Optional<UnifyPair> reduceWildcardLow(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof ExtendsType))
return Optional.empty();
return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
}
static Optional<UnifyPair> reduceWildcardLowRight(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof ExtendsType))
return Optional.empty();
return Optional.of(new UnifyPair(lhsType, ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
}
static Optional<UnifyPair> reduceWildcardUp(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof SuperType) || !(rhsType instanceof SuperType))
return Optional.empty();
return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), ((SuperType) lhsType).getSuperedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
}
static Optional<UnifyPair> reduceWildcardUpRight(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof SuperType))
return Optional.empty();
return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), lhsType, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
}
static Optional<Set<UnifyPair>> reduceFunN(UnifyPair pair) {
if((pair.getPairOp() != PairOperator.SMALLERDOT)
&& (pair.getPairOp() != PairOperator.EQUALSDOT)) //PL 2017-10-03 hinzugefuegt
//da Regel auch fuer EQUALSDOT anwendbar
//TODO: fuer allen anderen Relationen noch pruefen
return Optional.empty();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof FunNType) || !(rhsType instanceof FunNType))
return Optional.empty();
FunNType funNLhsType = (FunNType) lhsType;
FunNType funNRhsType = (FunNType) rhsType;
if(funNLhsType.getN() != funNRhsType.getN())
return Optional.empty();
Set<UnifyPair> result = new HashSet<UnifyPair>();
if (pair.getPairOp() == PairOperator.SMALLERDOT) {
result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), funNRhsType.getTypeParams().get(funNRhsType.getTypeParams().size()-1), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) {
result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
}
}
else {// pair.getPairOp() == PairOperator.EQUALDOT
result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), funNRhsType.getTypeParams().get(funNRhsType.getTypeParams().size()-1), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) {
result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), funNLhsType.getTypeParams().get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
}
}
result.stream().forEach(x -> { UnifyType l = x.getLhsType();
if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); }
UnifyType r = x.getRhsType();
if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
} );
return Optional.of(result);
}
static Optional<Set<UnifyPair>> greaterFunN(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof FunNType) || !(rhsType instanceof PlaceholderType))
return Optional.empty();
FunNType funNLhsType = (FunNType) lhsType;
Set<UnifyPair> result = new HashSet<UnifyPair>();
Integer variance = ((PlaceholderType)rhsType).getVariance();
Integer inversVariance = distributeVariance.inverseVariance(variance);
UnifyType[] freshPlaceholders = new UnifyType[funNLhsType.getTypeParams().size()];
for(int i = 0; i < freshPlaceholders.length-1; i++) {
freshPlaceholders[i] = PlaceholderType.freshPlaceholder();
((PlaceholderType)freshPlaceholders[i]).setVariance(inversVariance);
}
freshPlaceholders[freshPlaceholders.length-1] = PlaceholderType.freshPlaceholder();
((PlaceholderType)freshPlaceholders[freshPlaceholders.length-1]).setVariance(variance);
result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), freshPlaceholders[funNLhsType.getTypeParams().size()-1], PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) {
result.add(new UnifyPair(freshPlaceholders[i], funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
}
result.add(new UnifyPair(rhsType, funNLhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
result.stream().forEach(x -> { UnifyType l = x.getLhsType();
if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); }
UnifyType r = x.getRhsType();
if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
} );
return Optional.of(result);
}
static Optional<Set<UnifyPair>> smallerFunN(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof FunNType))
return Optional.empty();
FunNType funNRhsType = (FunNType) rhsType;
Set<UnifyPair> result = new HashSet<UnifyPair>();
Integer variance = ((PlaceholderType)lhsType).getVariance();
Integer inversVariance = distributeVariance.inverseVariance(variance);
UnifyType[] freshPlaceholders = new UnifyType[funNRhsType.getTypeParams().size()];
for(int i = 0; i < freshPlaceholders.length-1; i++) {
freshPlaceholders[i] = PlaceholderType.freshPlaceholder();
((PlaceholderType)freshPlaceholders[i]).setVariance(inversVariance);
}
freshPlaceholders[freshPlaceholders.length-1] = PlaceholderType.freshPlaceholder();
((PlaceholderType)freshPlaceholders[freshPlaceholders.length-1]).setVariance(variance);
result.add(new UnifyPair(freshPlaceholders[funNRhsType.getTypeParams().size()-1], funNRhsType.getTypeParams().get(funNRhsType.getTypeParams().size()-1), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
for(int i = 0; i < funNRhsType.getTypeParams().size()-1; i++) {
result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), freshPlaceholders[i], PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
}
result.add(new UnifyPair(lhsType, funNRhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
result.stream().forEach(x -> { UnifyType l = x.getLhsType();
if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); }
UnifyType r = x.getRhsType();
if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
} );
return Optional.of(result);
}
static Optional<UnifyPair> reduceTph(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof ReferenceType))
return Optional.empty();
return Optional.of(new UnifyPair(lhsType, rhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
}
static Optional<Set<UnifyPair>> reduceTphExt(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof PlaceholderType))
return Optional.empty();
UnifyType extendedType = ((ExtendsType)lhsType).getExtendedType();
if (extendedType.equals(rhsType)) return Optional.empty(); //PL 2019-02-18 eingefügt ? extends a <.? a
boolean isGen = extendedType instanceof PlaceholderType && !((PlaceholderType) extendedType).isGenerated();
Set<UnifyPair> result = new HashSet<>();
if(isGen)
result.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
else {
UnifyType freshTph = PlaceholderType.freshPlaceholder();
result.add(new UnifyPair(rhsType, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
result.add(new UnifyPair(extendedType, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
}
return Optional.of(result);
}
static Optional<Set<UnifyPair>> reduceTphSup(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof SuperType) || !(rhsType instanceof PlaceholderType))
return Optional.empty();
UnifyType superedType = ((SuperType)lhsType).getSuperedType();
if (superedType.equals(rhsType)) return Optional.empty(); //PL 2019-02-18 eingefügt ? super a <.? a
boolean isGen = superedType instanceof PlaceholderType && !((PlaceholderType) superedType).isGenerated();
Set<UnifyPair> result = new HashSet<>();
if(isGen)
result.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
else {
UnifyType freshTph = PlaceholderType.freshPlaceholder();
result.add(new UnifyPair(rhsType, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
Set<UnifyType> fBounded = pair.getfBounded();
fBounded.add(lhsType);
result.add(new UnifyPair(freshTph, superedType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair(), fBounded));
}
return Optional.of(result);
}
}

View File

@@ -1,54 +0,0 @@
package de.dhbwstuttgart.unify2;
import de.dhbwstuttgart.typeinference.unify.model.*;
import de.dhbwstuttgart.unify2.model.UnifyConstraintSet;
import java.util.*;
public class TypeUnify {
public static Optional<Set<UnifyPair>> unifyOrConstraints(UnifyConstraintSet eq, FiniteClosure fc){
return eq.cartesianProductParallel().map(eqPrime -> unify(eqPrime, fc)).filter(Optional::isPresent).map(Optional::get).findAny();
}
public static Optional<Set<UnifyPair>> unify(Set<UnifyPair> eq, FiniteClosure fc){
/*
TODO: Hier könnte man prüfen, ob es überhaupt einen Sinn macht mit eq weiterzumachen
Es könnte eine über threads geteiltes Objekt geben (Feld in TypeUnify), welches unmögliche Klauseln lernt
*/
//Apply Reduce und Apply rules
Set<UnifyPair> res = RuleSet.applyTypeUnificationRules(eq, fc);
//Split result
/*
* Step 2 and 3: Create a subset eq1s of pairs where both sides are TPH and eq2s of the other pairs
*/
Set<UnifyPair> eq1s = new HashSet<>();
Set<UnifyPair> eq2s = new HashSet<>();
for(UnifyPair pair : res) {
if (pair.getLhsType() instanceof PlaceholderType && pair.getRhsType() instanceof PlaceholderType)
eq1s.add(pair);
else
eq2s.add(pair);
}
Optional<UnifyConstraintSet> step4Res = Unify.step4(eq1s, eq2s, fc);
//Falls step4 etwas liefert, dann subst und rekursiver unify aufruf anwenden:
return step4Res.flatMap(constraintSet ->
constraintSet.cartesianProductParallel().map(toSubst -> {
Optional<Set<UnifyPair>> substitutionResult = Unify.subst(toSubst); //hier substituieren
//if it changed:
if (substitutionResult.isPresent()) {
return unify(substitutionResult.get(), fc);
}else{
//TODO: return the result
return Optional.of(toSubst);
}
}).filter(it -> it.isPresent()).map(Optional::get).findAny());
}
}

View File

@@ -1,340 +0,0 @@
package de.dhbwstuttgart.unify2;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.*;
import de.dhbwstuttgart.unify2.model.UnifyConstraintSet;
import de.dhbwstuttgart.unify2.model.UnifyOderConstraint;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
public class Unify {
/**
* Creates sets of pairs specified in the fourth step. Does not calculate cartesian products.
* @return The set of the eight cases (without empty sets). Each case is a set, containing sets generated
* from the pairs that matched the case. Each generated set contains singleton sets or sets with few elements
* (as in case 1 where sigma is added to the innermost set).
*/
public static Optional<UnifyConstraintSet> step4(Set<UnifyPair> eq1s, Set<UnifyPair> eq2s, FiniteClosure fc) {
Set<UnifyOderConstraint> result = new HashSet<>(8);
for(UnifyPair pair : eq2s) {
PairOperator pairOp = pair.getPairOp();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
// Case 1: (a <. Theta')
if(pairOp == PairOperator.SMALLERDOT && lhsType instanceof PlaceholderType)
result.add(unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), fc));
// Case 2: (a <.? ? ext Theta')
else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType)
result.add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), fc));
// Case 3: (a <.? ? sup Theta')
else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType)
result.add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, fc));
// Case 4 was replaced by an inference rule
// Case 4: (a <.? Theta')
//else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType)
// result.get(3).add(unifyCase4((PlaceholderType) lhsType, rhsType, fc));
// Case 5: (Theta <. a)
else if(pairOp == PairOperator.SMALLERDOT && rhsType instanceof PlaceholderType)
result.add(unifyCase5(lhsType, (PlaceholderType) rhsType, fc));
// Case 6 was replaced by an inference rule.
// Case 6: (? ext Theta <.? a)
//else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof ExtendsType && rhsType instanceof PlaceholderType)
// result.get(5).add(unifyCase6((ExtendsType) lhsType, (PlaceholderType) rhsType, fc));
// Case 7 was replaced by an inference rule
// Case 7: (? sup Theta <.? a)
//else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof SuperType && rhsType instanceof PlaceholderType)
// result.get(6).add(unifyCase7((SuperType) lhsType, (PlaceholderType) rhsType, fc));
// Case 8: (Theta <.? a)
else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType)
result.add(unifyCase8(lhsType, (PlaceholderType) rhsType, fc));
// Case unknown: If a pair fits no other case, then the type unification has failed.
// Through application of the rules, every pair should have one of the above forms.
// Pairs that do not have one of the aboves form are contradictory.
else {
return Optional.empty();
}
}
result.add(new UnifyOderConstraint(Set.of(eq1s)));
// Filter empty sets or sets that only contain an empty set.
//Andi: Why? Should they exist? this should be an error then
return Optional.of(new UnifyConstraintSet(result));
}
/**
* Cartesian product Case 1: (a <. Theta')
*/
static UnifyOderConstraint unifyCase1(PlaceholderType a, UnifyType thetaPrime, FiniteClosure fc) {
Set<Set<UnifyPair>> result = new HashSet<>();
boolean allGen = thetaPrime.getTypeParams().size() > 0;
for(UnifyType t : thetaPrime.getTypeParams())
if(!(t instanceof PlaceholderType) || !((PlaceholderType) t).isGenerated()) {
allGen = false;
break;
}
Set<UnifyType> cs = fc.getAllTypesByName(thetaPrime.getName());
cs.add(thetaPrime);
for(UnifyType c : cs) {
Set<UnifyType> thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new));
//thetaQs.add(thetaPrime);
Set<UnifyType> thetaQPrimes = new HashSet<>();
TypeParams cParams = c.getTypeParams();
if(cParams.size() == 0)
thetaQPrimes.add(c);
else {
ArrayList<Set<UnifyType>> candidateParams = new ArrayList<>();
for(UnifyType param : cParams)
candidateParams.add(fc.grArg(param, new HashSet<>()));
for(TypeParams tp : permuteParams(candidateParams))
thetaQPrimes.add(c.setTypeParams(tp));
}
for(UnifyType tqp : thetaQPrimes) {
Optional<Unifier> opt = MartelliMontanariUnify.unify(tqp, thetaPrime);
if (!opt.isPresent())
continue;
Unifier unifier = opt.get();
unifier.swapPlaceholderSubstitutions(thetaPrime.getTypeParams());
Set<UnifyPair> substitutionSet = new HashSet<>();
for (Map.Entry<PlaceholderType, UnifyType> sigma : unifier)
substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT));
List<UnifyType> freshTphs = new ArrayList<>();
for (UnifyType tq : thetaQs) {
Set<UnifyType> smaller = fc.smaller(unifier.apply(tq), new HashSet<>());
for(UnifyType theta : smaller) {
Set<UnifyPair> resultPrime = new HashSet<>();
for(int i = 0; !allGen && i < theta.getTypeParams().size(); i++) {
if(freshTphs.size()-1 < i)
freshTphs.add(PlaceholderType.freshPlaceholder());
resultPrime.add(new UnifyPair(freshTphs.get(i), theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC));
}
if(allGen)
resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT));
else
resultPrime.add(new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT));
resultPrime.addAll(substitutionSet);
result.add(resultPrime);
}
}
}
}
return new UnifyOderConstraint(result);
}
/**
* Takes a set of candidates for each position and computes all possible permutations.
* @param candidates The length of the list determines the number of type params. Each set
* contains the candidates for the corresponding position.
*/
static Set<TypeParams> permuteParams(ArrayList<Set<UnifyType>> candidates) {
Set<TypeParams> result = new HashSet<>();
permuteParams(candidates, 0, result, new UnifyType[candidates.size()]);
return result;
}
/**
* Takes a set of candidates for each position and computes all possible permutations.
* @param candidates The length of the list determines the number of type params. Each set
* contains the candidates for the corresponding position.
* @param idx Idx for the current permutatiton.
* @param result Set of all permutations found so far
* @param current The permutation of type params that is currently explored
*/
static void permuteParams(ArrayList<Set<UnifyType>> candidates, int idx, Set<TypeParams> result, UnifyType[] current) {
if(candidates.size() == idx) {
result.add(new TypeParams(Arrays.copyOf(current, current.length)));
return;
}
Set<UnifyType> localCandidates = candidates.get(idx);
for(UnifyType t : localCandidates) {
current[idx] = t;
permuteParams(candidates, idx+1, result, current);
}
}
/**
* Cartesian Product Case 2: (a <.? ? ext Theta')
*/
static UnifyOderConstraint unifyCase2(PlaceholderType a, ExtendsType extThetaPrime, IFiniteClosure fc) {
Set<Set<UnifyPair>> result = new HashSet<>();
UnifyType aPrime = PlaceholderType.freshPlaceholder();
UnifyType extAPrime = new ExtendsType(aPrime);
UnifyType thetaPrime = extThetaPrime.getExtendedType();
Set<UnifyPair> resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, thetaPrime, PairOperator.SMALLERDOT));
result.add(resultPrime);
resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, extAPrime, PairOperator.EQUALSDOT));
resultPrime.add(new UnifyPair(aPrime, thetaPrime, PairOperator.SMALLERDOT));
result.add(resultPrime);
return new UnifyOderConstraint(result);
}
/**
* Cartesian Product Case 3: (a <.? ? sup Theta')
*/
static UnifyOderConstraint unifyCase3(PlaceholderType a, SuperType subThetaPrime, IFiniteClosure fc) {
Set<Set<UnifyPair>> result = new HashSet<>();
UnifyType aPrime = PlaceholderType.freshPlaceholder();
UnifyType supAPrime = new SuperType(aPrime);
UnifyType thetaPrime = subThetaPrime.getSuperedType();
Set<UnifyPair> resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(thetaPrime, a, PairOperator.SMALLERDOT));
result.add(resultPrime);
resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, supAPrime, PairOperator.EQUALSDOT));
resultPrime.add(new UnifyPair(thetaPrime, aPrime, PairOperator.SMALLERDOT));
result.add(resultPrime);
return new UnifyOderConstraint(result);
}
/**
* Cartesian Product Case 5: (Theta <. a)
*/
static UnifyOderConstraint unifyCase5(UnifyType theta, PlaceholderType a, IFiniteClosure fc) {
Set<Set<UnifyPair>> result = new HashSet<>();
boolean allGen = theta.getTypeParams().size() > 0;
for(UnifyType t : theta.getTypeParams())
if(!(t instanceof PlaceholderType) || !((PlaceholderType) t).isGenerated()) {
allGen = false;
break;
}
for(UnifyType thetaS : fc.greater(theta, new HashSet<>())) {
Set<UnifyPair> resultPrime = new HashSet<>();
UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()];
for(int i = 0; !allGen && i < freshTphs.length; i++) {
freshTphs[i] = PlaceholderType.freshPlaceholder();
resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC));
}
if(allGen)
resultPrime.add(new UnifyPair(a, thetaS, PairOperator.EQUALSDOT));
else
resultPrime.add(new UnifyPair(a, thetaS.setTypeParams(new TypeParams(freshTphs)), PairOperator.EQUALSDOT));
result.add(resultPrime);
}
return new UnifyOderConstraint(result);
}
/**
* Cartesian Product Case 8: (Theta <.? a)
*/
static UnifyOderConstraint unifyCase8(UnifyType theta, PlaceholderType a, IFiniteClosure fc) {
Set<Set<UnifyPair>> result = new HashSet<>();
//for(UnifyType thetaS : fc.grArg(theta)) {
Set<UnifyPair> resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT));
result.add(resultPrime);
UnifyType freshTph = PlaceholderType.freshPlaceholder();
resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT));
resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT));
result.add(resultPrime);
resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, new SuperType(freshTph), PairOperator.EQUALSDOT));
resultPrime.add(new UnifyPair(freshTph, theta, PairOperator.SMALLERDOT));
result.add(resultPrime);
//}
return new UnifyOderConstraint(result);
}
static Optional<Set<UnifyPair>> subst(Set<UnifyPair> pairs) {
HashMap<UnifyType, Integer> typeMap = new HashMap<>();
Stack<UnifyType> occuringTypes = new Stack<>();
for(UnifyPair pair : pairs) {
occuringTypes.push(pair.getLhsType());
occuringTypes.push(pair.getRhsType());
}
while(!occuringTypes.isEmpty()) {
UnifyType t1 = occuringTypes.pop();
if(!typeMap.containsKey(t1))
typeMap.put(t1, 0);
typeMap.put(t1, typeMap.get(t1)+1);
if(t1 instanceof ExtendsType)
occuringTypes.push(((ExtendsType) t1).getExtendedType());
if(t1 instanceof SuperType)
occuringTypes.push(((SuperType) t1).getSuperedType());
else
t1.getTypeParams().forEach(x -> occuringTypes.push(x));
}
Queue<UnifyPair> result1 = new LinkedList<UnifyPair>(pairs);
ArrayList<UnifyPair> result = new ArrayList<UnifyPair>();
boolean applied = false;
while(!result1.isEmpty()) {
UnifyPair pair = result1.poll();
PlaceholderType lhsType = null;
UnifyType rhsType;
if(pair.getPairOp() == PairOperator.EQUALSDOT
&& pair.getLhsType() instanceof PlaceholderType)
lhsType = (PlaceholderType) pair.getLhsType();
rhsType = pair.getRhsType(); //PL eingefuegt 2017-09-29 statt !((rhsType = pair.getRhsType()) instanceof PlaceholderType)
if(lhsType != null
//&& !((rhsType = pair.getRhsType()) instanceof PlaceholderType) //PL geloescht am 2017-09-29 Begründung: auch Typvariablen muessen ersetzt werden.
&& typeMap.get(lhsType) > 1 // The type occurs in more pairs in the set than just the recent pair.
&& !rhsType.getTypeParams().occurs(lhsType)
&& !((rhsType instanceof WildcardType) && ((WildcardType)rhsType).getWildcardedType().equals(lhsType))) //PL eigefuegt 2018-02-18
{
Unifier uni = new Unifier(lhsType, rhsType);
result = result.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(ArrayList::new));
result1 = result1.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(LinkedList::new));
Function<? super Constraint<UnifyPair>,? extends Constraint<UnifyPair>> applyUni = b -> b.stream().map(
x -> uni.apply(pair,x)).collect(Collectors.toCollection((b.getExtendConstraint() != null)
? () -> new Constraint<UnifyPair>(
b.getExtendConstraint().stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(Constraint::new)))
: () -> new Constraint<UnifyPair>()
));
applied = true;
}
result.add(pair);
}
return applied ? Optional.of(new HashSet<>(result)) : Optional.empty();
}
}

View File

@@ -1,11 +0,0 @@
package de.dhbwstuttgart.unify2;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import java.util.Set;
public class UnifyResult {
public UnifyResult(Set<UnifyPair> toSubst) {
}
}

View File

@@ -0,0 +1,17 @@
package de.dhbwstuttgart.unify2.model;
public class Result<A> {
private final A v;
private Result(A a, UnifyError e){
this.v = a;
}
public static <A> Result<A> of(A a){
return new Result(a, null);
}
public static <A> Result<A> error(UnifyError error){
return new Result(null, error);
}
}

View File

@@ -1,124 +0,0 @@
package de.dhbwstuttgart.unify2.model;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import java.util.*;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
/*
OrC1 OrC2 OrC3 -> Constraints
Step4: OrC1 OrC2/c OrC3 OrC4
Tiefensuche, neue UnifyConstraints erstellen
Wie wird ConstraintSet geändert?
wird nicht gebraucht:
( map -> bei subst
Alle Constraints ändern, neues ConstraintSet zurückgeben )
Step 4 bildet anschließend das karthesische Produkt und muss über alle Möglichkeiten iterieren
die erste möglichkeit vom karthesischen produkt nehmen, subst schritt ausführen und mit dem Ergebnis (einzelnes Constraint Set) weiterarbeiten
*/
public class UnifyConstraintSet {
Set<UnifyOderConstraint> oderConstraints = new HashSet<>();
public UnifyConstraintSet(Set<UnifyOderConstraint> constraints){
if(constraints.isEmpty())throw new RuntimeException("Empty constraint set");
this.oderConstraints = constraints;
}
@Override
public String toString(){
BinaryOperator<String> b = (x, y) -> x+y;
return "ODER:" + this.oderConstraints.stream().reduce("", (x,y) -> x.toString()+ "\n" +y, b);
}
/*
Cartesian product als optimierter Stream
- Ein Split teilt das Set so auf, dass der zweite Thread jedes zweite Element behandelt
- Ein thread der jedes zweite element behandelt wird gesplittet indem
1 2 1 2 1 2 1 2 => (o = 0, n = 2), (o = 1, n = 2)
1 2 1 3 1 2 1 3 => (o = 0, n = 2), (o = 1, n = 4), (o = 3, n = 4)
*/
private class ConstraintSpliterator implements Spliterator<Set<UnifyPair>> {
private List<UnifyOderConstraint> constraints;
private long i = 0;
private long iterationFactor = 1;
private long max = 0;
private List<Integer> sizes;
private List<Long> bases = new ArrayList<>();
ConstraintSpliterator(List<UnifyOderConstraint> constraints){
this.constraints = constraints;
sizes = constraints.stream().map(UnifyOderConstraint::getSize).collect(Collectors.toList());
long base = 1;
for(int size : sizes){
bases.add(base);
base *= size;
}
i = 0;
max = estimateSize() - 1;
}
ConstraintSpliterator(List<UnifyOderConstraint> constraints, long start, long factor){
this(constraints);
i = start;
this.iterationFactor = factor;
}
@Override
public boolean tryAdvance(Consumer<? super Set<UnifyPair>> consumer) {
if(i > max) return false;
consumer.accept(get(i));
i++;
return true;
}
private Set<UnifyPair> get(long num){
Set<UnifyPair> ret = new HashSet<>();
Iterator<Long> baseIt = bases.iterator();
for(UnifyOderConstraint constraint : constraints){
ret.addAll(constraint.get((int) ((num/baseIt.next())%constraint.getSize())));
}
return ret;
}
@Override
public Spliterator<Set<UnifyPair>> trySplit() {
if(max - (i+iterationFactor * 2) < 0) return null;
long iNext = i + iterationFactor;
iterationFactor *= 2;
return new UnifyConstraintSet.ConstraintSpliterator(constraints, iNext, iterationFactor);
}
@Override
public long estimateSize() {
long ret = 1;
for (int size : sizes)ret*=size;
return ret;
}
@Override
public int characteristics() {
return ORDERED | SIZED | IMMUTABLE | NONNULL;
}
}
public Stream<Set<UnifyPair>> cartesianProductParallel(){
return StreamSupport.stream(new UnifyConstraintSet.ConstraintSpliterator(oderConstraints.stream().collect(Collectors.toList())), true);
}
public Stream<Set<UnifyPair>> cartesianProductParallel(Comparator<Set<UnifyPair>> prioritiser){
return StreamSupport.stream(new UnifyConstraintSet.ConstraintSpliterator(oderConstraints.stream().collect(Collectors.toList())), true);
}
}

View File

@@ -1,30 +0,0 @@
package de.dhbwstuttgart.unify2.model;
import de.dhbwstuttgart.typeinference.unify.model.Pair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import java.util.HashSet;
import java.util.Set;
public class UnifyConstraintSetBuilder {
private Set<UnifyPair> undConstraints = new HashSet<>();
private Set<UnifyOderConstraint> oderConstraints = new HashSet<>();
private boolean done = false;
public void addUndConstraint(UnifyPair p){
undConstraints.add(p);
}
public void addOderConstraint(UnifyOderConstraint orConstraint) {
oderConstraints.add(orConstraint);
}
public UnifyConstraintSet build(){
if(done)throw new RuntimeException("Trying to build cartesian product twice");
this.done = true;
if(!undConstraints.isEmpty())
oderConstraints.add(new UnifyOderConstraint(Set.of(undConstraints)));
return new UnifyConstraintSet(oderConstraints);
}
}

View File

@@ -0,0 +1,5 @@
package de.dhbwstuttgart.unify2.model;
public class UnifyError {
}

View File

@@ -1,27 +0,0 @@
package de.dhbwstuttgart.unify2.model;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class UnifyOderConstraint {
private final List<Set<UnifyPair>> cons;
public UnifyOderConstraint(Set<Set<UnifyPair>> orCons){
if(orCons.isEmpty())throw new RuntimeException("Empty constraint set");
for(Set<UnifyPair> c : orCons){
if(c.isEmpty())throw new RuntimeException("Empty constraint set");
}
this.cons = orCons.stream().collect(Collectors.toList());
}
public int getSize(){
return cons.size();
}
public Set<UnifyPair> get(int l) {
return cons.get(l);
}
}

View File

@@ -40,7 +40,8 @@ public class AllgemeinTest {
//String className = "FCTest3"; //String className = "FCTest3";
//String className = "Var"; //String className = "Var";
//String className = "Put"; //String className = "Put";
String className = "Cycle"; //String className = "Twice";
String className = "TestSubTypless";
//PL 2019-10-24: genutzt fuer unterschiedliche Tests //PL 2019-10-24: genutzt fuer unterschiedliche Tests
path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/" + className + ".jav"; path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/" + className + ".jav";
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav"; //path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";

View File

@@ -0,0 +1,148 @@
package inferWildcards;
import static org.junit.Assert.assertThat;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
import de.dhbwstuttgart.typeinference.result.ResultPair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
public class TestInferWildcardsFields
{
private String resourceFilePath;
private String resourceDirPath;
@Before
public void setup () {
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
resourceFilePath = resourceDirPath + "/TestClassWildcardsFields.java";
}
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
File[] files1 = { new File(resourceFilePath) };
return new JavaTXCompiler(files1);
}
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
File[] files1 = { new File(resourceFilePath) };
return new JavaTXCompilerWildcards(files1);
}
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
JavaTXCompiler javaTXCompiler) {
System.out.println("\nReplacements:");
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
}
private static List<ResultSet> generateExpectedTypeInferResult (JavaTXCompilerWildcards compiler) {
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = compiler.getTphMap();
ArrayList<ResultSet> list = new ArrayList<>();
tphMap.forEach( (tph, t) -> {
ResultPair r = new PairTPHequalRefTypeOrWildcardType(tph,
new RefType(new JavaClassName("java.lang.String"), new NullToken()));
HashSet<ResultPair> set = new HashSet<>();
set.add(r);
list.add(new ResultSet(set));
});
return list;
}
@Test
public void testGenerateTph () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Generate TPH --------------\n");
JavaTXCompiler javaTXCompiler = getStandardCompiler();
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
javaTXCompiler);
System.out.println(generateTph);
assertThat("Number of TPH is 4", 4, CoreMatchers.is(generateTph.size()));
}
@Test
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Generate Constraints --------------\n");
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
.getTphMap();
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
System.out.println(generateConstraints);
int size = 0;
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
for (Constraint<Pair> c : l)
size += c.size();
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
}
@Test
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Combined Constraints --------------\n");
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
System.out.println(constraints);
}
@Test
public void testTypeInference () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
System.out.println(typeInference);
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
CoreMatchers.anything());
}
@Test
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
assertThat("Generation Succeeded", null, CoreMatchers.anything());
}
@Test
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
assertThat("Generation Succeeded", null, CoreMatchers.anything());
}
}

View File

@@ -0,0 +1,125 @@
package inferWildcards;
import static org.junit.Assert.assertThat;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
public class TestInferWildcardsMap
{
private String resourceFilePath;
private String resourceDirPath;
@Before
public void setup () {
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
resourceFilePath = resourceDirPath + "/TestClassWildcardsMap.java";
}
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
File[] files1 = { new File(resourceFilePath) };
return new JavaTXCompiler(files1);
}
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
File[] files1 = { new File(resourceFilePath) };
return new JavaTXCompilerWildcards(files1);
}
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
JavaTXCompiler javaTXCompiler) {
System.out.println("\nReplacements:");
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
}
@Test
public void testGenerateTph () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Generate TPH --------------\n");
JavaTXCompiler javaTXCompiler = getStandardCompiler();
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
javaTXCompiler);
System.out.println(generateTph);
assertThat("Number of TPH is 6", 6, CoreMatchers.is(generateTph.size()));
}
@Test
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Generate Constraints --------------\n");
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
.getTphMap();
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
System.out.println(generateConstraints);
int size = 0;
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
for (Constraint<Pair> c : l)
size += c.size();
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
}
@Test
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Combined Constraints --------------\n");
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
System.out.println(constraints);
}
@Test
public void testTypeInference () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
System.out.println(typeInference);
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
CoreMatchers.anything());
}
@Test
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
assertThat("Generation Succeeded", null, CoreMatchers.anything());
}
@Test
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
assertThat("Generation Succeeded", null, CoreMatchers.anything());
}
}

View File

@@ -0,0 +1,126 @@
package inferWildcards;
import static org.junit.Assert.assertThat;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
public class TestInferWildcardsMapNested
{
private String resourceFilePath;
private String resourceDirPath;
@Before
public void setup () {
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
resourceFilePath = resourceDirPath + "/TestClassWildcardsMapNested.java";
}
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
File[] files1 = { new File(resourceFilePath) };
return new JavaTXCompiler(files1);
}
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
File[] files1 = { new File(resourceFilePath) };
return new JavaTXCompilerWildcards(files1);
}
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
JavaTXCompiler javaTXCompiler) {
System.out.println("\nReplacements:");
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
}
@Test
public void testGenerateTph () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Generate TPH --------------\n");
JavaTXCompiler javaTXCompiler = getStandardCompiler();
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
javaTXCompiler);
System.out.println(generateTph);
assertThat("Number of TPH is 9", 9, CoreMatchers.is(generateTph.size()));
}
@Test
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Generate Constraints --------------\n");
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
.getTphMap();
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
System.out.println(generateConstraints);
int size = 0;
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
for (Constraint<Pair> c : l)
size += c.size();
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
}
@Test
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Combined Constraints --------------\n");
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
System.out.println(constraints);
}
@Test
public void testTypeInference () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
System.out.println(typeInference);
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
CoreMatchers.anything());
}
@Test
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
assertThat("Generation Succeeded", null, CoreMatchers.anything());
}
@Test
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
assertThat("Generation Succeeded", null, CoreMatchers.anything());
}
}

View File

@@ -0,0 +1,125 @@
package inferWildcards;
import static org.junit.Assert.assertThat;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
public class TestInferWildcardsNested
{
private String resourceFilePath;
private String resourceDirPath;
@Before
public void setup () {
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
resourceFilePath = resourceDirPath + "/TestClassWildcardsNested.java";
}
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
File[] files1 = { new File(resourceFilePath) };
return new JavaTXCompiler(files1);
}
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
File[] files1 = { new File(resourceFilePath) };
return new JavaTXCompilerWildcards(files1);
}
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
JavaTXCompiler javaTXCompiler) {
System.out.println("\nReplacements:");
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
}
@Test
public void testGenerateTph () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Generate TPH --------------\n");
JavaTXCompiler javaTXCompiler = getStandardCompiler();
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
javaTXCompiler);
System.out.println(generateTph);
assertThat("Number of TPH is 6", 6, CoreMatchers.is(generateTph.size()));
}
@Test
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Generate Constraints --------------\n");
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
.getTphMap();
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
System.out.println(generateConstraints);
int size = 0;
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
for (Constraint<Pair> c : l)
size += c.size();
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
}
@Test
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Combined Constraints --------------\n");
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
System.out.println(constraints);
}
@Test
public void testTypeInference () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
System.out.println(typeInference);
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
CoreMatchers.anything());
}
@Test
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
assertThat("Generation Succeeded", null, CoreMatchers.anything());
}
@Test
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
assertThat("Generation Succeeded", null, CoreMatchers.anything());
}
}

View File

@@ -0,0 +1,125 @@
package inferWildcards;
import static org.junit.Assert.assertThat;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
public class TestInferWildcardsParamType
{
private String resourceFilePath;
private String resourceDirPath;
@Before
public void setup () {
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
resourceFilePath = resourceDirPath + "/TestClassWildcardsParamType.java";
}
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
File[] files1 = { new File(resourceFilePath) };
return new JavaTXCompiler(files1);
}
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
File[] files1 = { new File(resourceFilePath) };
return new JavaTXCompilerWildcards(files1);
}
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
JavaTXCompiler javaTXCompiler) {
System.out.println("\nReplacements:");
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
}
@Test
public void testGenerateTph () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Generate TPH --------------\n");
JavaTXCompiler javaTXCompiler = getStandardCompiler();
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
javaTXCompiler);
System.out.println(generateTph);
assertThat("Number of TPH is 4", 4, CoreMatchers.is(generateTph.size()));
}
@Test
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Generate Constraints --------------\n");
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
.getTphMap();
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
System.out.println(generateConstraints);
int size = 0;
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
for (Constraint<Pair> c : l)
size += c.size();
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
}
@Test
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Combined Constraints --------------\n");
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
System.out.println(constraints);
}
@Test
public void testTypeInference () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
System.out.println(typeInference);
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
CoreMatchers.anything());
}
@Test
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
assertThat("Generation Succeeded", null, CoreMatchers.anything());
}
@Test
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
assertThat("Generation Succeeded", null, CoreMatchers.anything());
}
}

View File

@@ -0,0 +1,125 @@
package inferWildcards;
import static org.junit.Assert.assertThat;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
public class TestInferWildcardsSingle
{
private String resourceFilePath;
private String resourceDirPath;
@Before
public void setup () {
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
resourceFilePath = resourceDirPath + "/TestClassWildcardsSingle.java";
}
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
File[] files1 = { new File(resourceFilePath) };
return new JavaTXCompiler(files1);
}
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
File[] files1 = { new File(resourceFilePath) };
return new JavaTXCompilerWildcards(files1);
}
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
JavaTXCompiler javaTXCompiler) {
System.out.println("\nReplacements:");
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
}
@Test
public void testGenerateTph () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Generate TPH --------------\n");
JavaTXCompiler javaTXCompiler = getStandardCompiler();
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
javaTXCompiler);
System.out.println(generateTph);
assertThat("Number of TPH is 3", 3, CoreMatchers.is(generateTph.size()));
}
@Test
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Generate Constraints --------------\n");
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
.getTphMap();
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
System.out.println(generateConstraints);
int size = 0;
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
for (Constraint<Pair> c : l)
size += c.size();
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
}
@Test
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Combined Constraints --------------\n");
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
System.out.println(constraints);
}
@Test
public void testTypeInference () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
System.out.println(typeInference);
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
CoreMatchers.anything());
}
@Test
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
assertThat("Generation Succeeded", null, CoreMatchers.anything());
}
@Test
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
assertThat("Generation Succeeded", null, CoreMatchers.anything());
}
}

View File

@@ -0,0 +1,125 @@
package inferWildcards;
import static org.junit.Assert.assertThat;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils;
import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards;
import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
public class TestInferWildcardsSingleLib
{
private String resourceFilePath;
private String resourceDirPath;
@Before
public void setup () {
resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
resourceFilePath = resourceDirPath + "/TestClassWildcardsSingleLib.java";
}
private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException {
File[] files1 = { new File(resourceFilePath) };
return new JavaTXCompiler(files1);
}
private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException {
File[] files1 = { new File(resourceFilePath) };
return new JavaTXCompilerWildcards(files1);
}
private static Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph (
JavaTXCompiler javaTXCompiler) {
System.out.println("\nReplacements:");
return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler);
}
@Test
public void testGenerateTph () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Generate TPH --------------\n");
JavaTXCompiler javaTXCompiler = getStandardCompiler();
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> generateTph = generateTph(
javaTXCompiler);
System.out.println(generateTph);
assertThat("Number of TPH is 2", 2, CoreMatchers.is(generateTph.size()));
}
@Test
public void testGeneratedConstraints () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Generate Constraints --------------\n");
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap = javaTXCompilerWildcards
.getTphMap();
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
System.out.println(generateConstraints);
int size = 0;
for (Set<Constraint<Pair>> l : generateConstraints.getOderConstraints())
for (Constraint<Pair> c : l)
size += c.size();
assertThat("Number of Generated Constraints", tphMap.size() * 3, CoreMatchers.is(size));
}
@Test
public void testCombinedConstraints () throws ClassNotFoundException, IOException {
System.out.println("\n--------- Test Combined Constraints --------------\n");
JavaTXCompilerWildcards javaTXCompilerWildcards = getWildcardsCompiler();
ConstraintSet<Pair> constraints = javaTXCompilerWildcards.getConstraints();
System.out.println(constraints);
}
@Test
public void testTypeInference () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
List<ResultSet> typeInference = wildcardsCompiler.typeInference();
System.out.println(typeInference);
assertThat("Type Inference Results containing the correct Wildcard results", typeInference,
CoreMatchers.anything());
}
@Test
public void testGenrationBytecode () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"));
assertThat("Generation Succeeded", null, CoreMatchers.anything());
}
@Test
public void testGenrationSourceCode () throws ClassNotFoundException, IOException {
JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler();
wildcardsCompiler.generateSourceCode(new File(resourceDirPath + "/generatedSC"));
assertThat("Generation Succeeded", null, CoreMatchers.anything());
}
}

View File

@@ -1,3 +1,4 @@
/*
package insertGenerics; package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
@@ -12,11 +13,13 @@ import java.util.List;
public class FamilyOfGeneratedGenericsTest extends TestCase { public class FamilyOfGeneratedGenericsTest extends TestCase {
public void testIdentityMethod(){ public void testIdentityMethod(){
/* */
/*
Example method: Example method:
A id(B i) return i; A id(B i) return i;
gives constraint: B <. A and A <. Object, which are method constraints gives constraint: B <. A and A <. Object, which are method constraints
*/ *//*
List<TPHConstraint> inputConstraints = new ArrayList<>(); List<TPHConstraint> inputConstraints = new ArrayList<>();
inputConstraints.add(new TPHConstraint("B", "A", TPHConstraint.Relation.EXTENDS)); inputConstraints.add(new TPHConstraint("B", "A", TPHConstraint.Relation.EXTENDS));
@@ -29,17 +32,20 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
assertTrue(classConstraints.isEmpty()); assertTrue(classConstraints.isEmpty());
/* */
/*
MethodConstraints should be the same as the input constraint MethodConstraints should be the same as the input constraint
*/ *//*
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, new ArrayList<ClassConstraint>(), tphPositions);
assertTrue(methodConstraints.size() == 2); // List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, new ArrayList<ClassConstraint>(), tphPositions);
assertTrue(methodConstraints.get(0).getLeft().equals("B")); // assertTrue(methodConstraints.size() == 2);
assertTrue(methodConstraints.get(0).getRight().equals("A")); // assertTrue(methodConstraints.get(0).getLeft().equals("B"));
// assertTrue(methodConstraints.get(0).getRight().equals("A"));
} }
public void testClassField(){ public void testClassField(){
/* */
/*
class Example{ class Example{
A f; A f;
B fReturn(){ B fReturn(){
@@ -47,7 +53,8 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
} }
} }
gives constraint: A <. B and B <. Object which are class constraints gives constraint: A <. B and B <. Object which are class constraints
*/ *//*
List<TPHConstraint> inputConstraints = new ArrayList<>(); List<TPHConstraint> inputConstraints = new ArrayList<>();
inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS)); inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS));
@@ -58,18 +65,22 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
PairTphMethod<PositionFinder.Position, String> posOfB = new PairTphMethod<>(PositionFinder.Position.METHOD, "fReturn"); PairTphMethod<PositionFinder.Position, String> posOfB = new PairTphMethod<>(PositionFinder.Position.METHOD, "fReturn");
tphPositions.put("B", posOfB); tphPositions.put("B", posOfB);
/* */
/*
ClassConstraints should not be the same as the input constraint ClassConstraints should not be the same as the input constraint
*/ *//*
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
System.out.println(classConstraints); System.out.println(classConstraints);
assertTrue(classConstraints.size() == 2); assertTrue(classConstraints.size() == 2);
//assertTrue(classConstraints.get(0).getLeft().equals("A")); //assertTrue(classConstraints.get(0).getLeft().equals("A"));
//assertTrue(classConstraints.get(0).getRight().equals("B")); //assertTrue(classConstraints.get(0).getRight().equals("B"));
// HashMap<String, List<MethodConstraint>> methodConstraintsWithPosition = FamilyOfGeneratedGenerics.getMethodConstraintsWithPosition(inputConstraints,classConstraints,tphPositions,)
} }
public void testSecondLineOfClassConstraints() { public void testSecondLineOfClassConstraints() {
/* */
/*
class Example() { class Example() {
A a; A a;
B b = a; B b = a;
@@ -83,7 +94,8 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
return e; return e;
} }
} }
*/ *//*
List<TPHConstraint> inputConstraints = new ArrayList<>(); List<TPHConstraint> inputConstraints = new ArrayList<>();
inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS)); inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS));
@@ -109,17 +121,18 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
System.out.println(classConstraints); System.out.println(classConstraints);
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions); // List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions);
System.out.println(methodConstraints); // System.out.println(methodConstraints);
assertFalse(classConstraints.isEmpty()); assertFalse(classConstraints.isEmpty());
assertTrue(classConstraints.size() == 6); assertTrue(classConstraints.size() == 6);
assertFalse(methodConstraints.isEmpty()); // assertFalse(methodConstraints.isEmpty());
assertTrue(methodConstraints.size() == 5); // assertTrue(methodConstraints.size() == 2);
} }
public void testTPHsAndGenerics() { public void testTPHsAndGenerics() {
/* */
/*
class TPHsAndGenerics { class TPHsAndGenerics {
Fun1<A,B> id = x -> x; Fun1<A,B> id = x -> x;
C id2 (D x) { C id2 (D x) {
@@ -133,7 +146,8 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
return b; return b;
} }
} }
*/ *//*
List<TPHConstraint> inputConstraints = new ArrayList<>(); List<TPHConstraint> inputConstraints = new ArrayList<>();
inputConstraints.add(new TPHConstraint("A","B", TPHConstraint.Relation.EXTENDS)); inputConstraints.add(new TPHConstraint("A","B", TPHConstraint.Relation.EXTENDS));
@@ -169,13 +183,13 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
System.out.println(classConstraints); System.out.println(classConstraints);
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions); // List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, classConstraints, tphPositions);
System.out.println(methodConstraints); // System.out.println(methodConstraints);
assertFalse(classConstraints.isEmpty()); assertFalse(classConstraints.isEmpty());
assertTrue(classConstraints.size() == 3); assertTrue(classConstraints.size() == 3);
assertFalse(methodConstraints.isEmpty()); // assertFalse(methodConstraints.isEmpty());
assertTrue(methodConstraints.size()==9); // assertTrue(methodConstraints.size()==9);
} }
@@ -195,7 +209,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
HashMap<String, PairTphMethod<PositionFinder.Position, String>> allTphsNew = FamilyOfGeneratedGenerics.positionConverter(allTphsOld, listOfMethodsAndTphs); HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> allTphsNew = FamilyOfGeneratedGenerics.positionConverter(allTphsOld, listOfMethodsAndTphs);
System.out.println(allTphsNew); System.out.println(allTphsNew);
//was tun wenn zwei (oder mehr) Methoden gleiches TPH enthalten? //was tun wenn zwei (oder mehr) Methoden gleiches TPH enthalten?
//ist dies möglich oder werden die TPHs immer verschieden initialisiert und dann erst am Ende gemappt? //ist dies möglich oder werden die TPHs immer verschieden initialisiert und dann erst am Ende gemappt?
@@ -211,4 +225,4 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
} }
} }*/

View File

@@ -1,30 +0,0 @@
package insertGenerics;
import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import junit.framework.TestResult;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class MethodsTest {
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
public static final String fileDirectory = rootDirectory + "TestGGFinder.jav";
@Test
public void testVisit(ClassOrInterface coi) throws IOException, ClassNotFoundException {
JavaTXCompiler compiler = new JavaTXCompiler(new File(fileDirectory));
SourceFile sf = compiler.sourceFiles.get(compiler.sourceFiles.keySet());
List<ResultSet> results = compiler.typeInference();
GeneratedGenericsFinder ggf = new GeneratedGenericsFinder(sf, results);
ClassOrInterface coiHere = coi;
ggf.visit(coiHere);
//assert results.size()>0;
}
}

View File

@@ -0,0 +1,112 @@
package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TestAny {
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
@BeforeClass
public static void resetNamesOfTypePlaceholder() {
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
}
@Test
public void ggFinder() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"TestAny.jav"));
}
private static class TestResultSet{
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
}
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
classConstraintsTest.add(new ClassConstraint("N", "O", Relation.EXTENDS));
classConstraintsTest.add(new ClassConstraint("N", "U", Relation.EXTENDS));
classConstraintsTest.add(new ClassConstraint("U", "O", Relation.EXTENDS));
classConstraintsTest.add(new ClassConstraint("O", "java/lang/Object", Relation.EXTENDS));
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
Set<MethodConstraint> lmc;
lmc = new HashSet<>();
lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH RanyMethod()", lmc);
lmc = new HashSet<>();
methodConstraintsWithPositionTest.put("TPH UotherMethod(TPH U)", lmc);
FamilyOfGeneratedGenerics fogg = compiler.fogg;
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
//compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles);
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
System.out.println(ASTTypePrinter.print(sf));
System.out.println(ASTPrinter.print(sf));
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
assert results.size()>0;
Set<String> insertedTypes = new HashSet<>();
for(ResultSet resultSet : results){
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
assert result.size()>0;
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
for(TypeInsert tip : result){
insertedTypes.add(tip.insert(content));
}
}
for(String s : insertedTypes){
System.out.println(s);
}
}
return new TestResultSet();
}
static String readFile(String path, Charset encoding)
throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}
}

View File

@@ -8,6 +8,8 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.io.File;
@@ -20,13 +22,18 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
public class TryTest { public class TestClassField {
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/"; public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
@BeforeClass
public static void resetNamesOfTypePlaceholder() {
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
}
@Test @Test
public void ggFinder() throws IOException, ClassNotFoundException { public void ggFinder() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"TestGGFinder.jav")); execute(new File(rootDirectory+"TestClassField.jav"));
} }
private static class TestResultSet{ private static class TestResultSet{
@@ -34,25 +41,9 @@ public class TryTest {
} }
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
//filesToTest.add(new File(rootDirectory+"fc.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda3.jav"));
//filesToTest.add(new File(rootDirectory+"Vector.jav"));
//filesToTest.add(new File(rootDirectory+"Generics.jav"));
//filesToTest.add(new File(rootDirectory+"MethodsEasy.jav"));
//filesToTest.add(new File(rootDirectory+"Matrix.jav"));
//filesToTest.add(new File(rootDirectory+"Import.jav"));
// //filesToTest.add(new File(rootDirectory+"Faculty.jav"));
// //filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
// //filesToTest.add(new File(rootDirectory+"test.jav"));
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
for(File f : compiler.sourceFiles.keySet()){ for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f); SourceFile sf = compiler.sourceFiles.get(f);
// System.out.println(ASTTypePrinter.print(sf));
// System.out.println("---------------------------1");
// System.out.println(ASTPrinter.print(sf));
// System.out.println("---------------------------2");
} }
List<ResultSet> results = compiler.typeInference(); List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
@@ -60,9 +51,7 @@ public class TryTest {
for(File f : compiler.sourceFiles.keySet()){ for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f); SourceFile sf = compiler.sourceFiles.get(f);
System.out.println(ASTTypePrinter.print(sf)); System.out.println(ASTTypePrinter.print(sf));
// System.out.println("---------------------------3");
System.out.println(ASTPrinter.print(sf)); System.out.println(ASTPrinter.print(sf));
// System.out.println("---------------------------4");
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen //List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
assert results.size()>0; assert results.size()>0;
Set<String> insertedTypes = new HashSet<>(); Set<String> insertedTypes = new HashSet<>();
@@ -75,9 +64,7 @@ public class TryTest {
} }
} }
for(String s : insertedTypes){ for(String s : insertedTypes){
System.out.println("---------------------------51");
System.out.println(s); System.out.println(s);
System.out.println("---------------------------52");
} }
} }
return new TestResultSet(); return new TestResultSet();

View File

@@ -0,0 +1,112 @@
package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TestContraVariant {
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
@BeforeClass
public static void resetNamesOfTypePlaceholder() {
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
}
@Test
public void ggFinder() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"TestContraVariant.jav"));
}
private static class TestResultSet{
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
}
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
Set<MethodConstraint> lmc;
lmc = new HashSet<>();
lmc.add(new MethodConstraint("R", "O", Relation.EXTENDS));
lmc.add(new MethodConstraint("O", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH Rm(TPH O)", lmc);
lmc = new HashSet<>();
//lmc.add(new MethodConstraint("S", "O", Relation.EXTENDS));
lmc.add(new MethodConstraint("S", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH Rmain(TPH S)", lmc);
FamilyOfGeneratedGenerics fogg = compiler.fogg;
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
//compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles);
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
System.out.println(ASTTypePrinter.print(sf));
System.out.println(ASTPrinter.print(sf));
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
assert results.size()>0;
Set<String> insertedTypes = new HashSet<>();
for(ResultSet resultSet : results){
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
assert result.size()>0;
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
for(TypeInsert tip : result){
insertedTypes.add(tip.insert(content));
}
}
for(String s : insertedTypes){
System.out.println(s);
}
}
return new TestResultSet();
}
static String readFile(String path, Charset encoding)
throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}
}

View File

@@ -6,7 +6,6 @@ import de.dhbwstuttgart.bytecode.insertGenerics.*;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.io.BufferedReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@@ -53,10 +52,10 @@ public class TestExample42 {
@Test @Test
public void genericTest() { public void genericTest() {
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs()); // List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs());
System.out.println("ClassConstraints: " + classConstraints); // System.out.println("ClassConstraints: " + classConstraints);
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs()); // List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs());
System.out.println("MethodConstraints: " + methodConstraints); // System.out.println("MethodConstraints: " + methodConstraints);
List<TPHConstraint> testCons; List<TPHConstraint> testCons;
} }

View File

@@ -51,10 +51,10 @@ public class TestExample42_allInOneMethod {
@Test @Test
public void genericTest() { public void genericTest() {
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs()); // List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(fillConstraintsList(),fillPosOfTphs());
System.out.println("ClassConstraints: " + classConstraints); // System.out.println("ClassConstraints: " + classConstraints);
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs()); // List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(fillConstraintsList(),classConstraints,fillPosOfTphs(),);
System.out.println("MethodConstraints: " + methodConstraints); // System.out.println("MethodConstraints: " + methodConstraints);
List<TPHConstraint> testCons; List<TPHConstraint> testCons;
} }

View File

@@ -0,0 +1,99 @@
package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TestGGFinder {
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
private static ClassLoader loader;
private static Class<?> classToTest;
private static Object instanceOfClass;
private static String className = "TestGGFinder";
@BeforeClass
public static void resetNamesOfTypePlaceholder() {
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
}
@Test
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
execute(new File(rootDirectory+className+".jav"));
}
private static class TestResultSet{
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
classConstraintsTest.add(new ClassConstraint("S", "java/lang/Object", Relation.EXTENDS));
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
Set<MethodConstraint> lmc;
lmc = new HashSet<>();
lmc.add(new MethodConstraint("P", "AC", Relation.EXTENDS));
lmc.add(new MethodConstraint("AC", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH ACid(TPH P)", lmc);
lmc = new HashSet<>();
lmc.add(new MethodConstraint("T", "S", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH SsetA(TPH T)", lmc);
lmc = new HashSet<>();
lmc.add(new MethodConstraint("AC", "Y", Relation.EXTENDS));
lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS));
lmc.add(new MethodConstraint("P", "AC", Relation.EXTENDS));
lmc.add(new MethodConstraint("Y", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("voidm(TPH YTPH Z)", lmc);
FamilyOfGeneratedGenerics fogg = compiler.fogg;
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass(className);
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
return new TestResultSet();
}
}

View File

@@ -0,0 +1,112 @@
package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TestLocalVarLambda {
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
private static ClassLoader loader;
private static Class<?> classToTest;
private static Object instanceOfClass;
private static String className = "TestLocalVarLambda";
@BeforeClass
public static void resetNamesOfTypePlaceholder() {
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
}
@Test
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
execute(new File(rootDirectory+className+".jav"));
}
private static class TestResultSet{
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
FamilyOfGeneratedGenerics fogg = compiler.fogg;
Set<MethodConstraint> lmc;
lmc = new HashSet<>();
if (fogg.allConstraints.contains((new MethodConstraint("O", "ALU", Relation.EXTENDS)))) {
lmc.add(new MethodConstraint("O", "ALU", Relation.EXTENDS));
lmc.add(new MethodConstraint("DIU", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("ALU", "DIU", Relation.EXTENDS));
lmc.add(new MethodConstraint("SY", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH DIUm(TPH O)", lmc);
}
else if (fogg.allConstraints.contains((new MethodConstraint("O", "DIV", Relation.EXTENDS)))) {
lmc.add(new MethodConstraint("O", "DIV", Relation.EXTENDS));
lmc.add(new MethodConstraint("N", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("DIV", "N", Relation.EXTENDS));
lmc.add(new MethodConstraint("SY", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH Nm(TPH O)", lmc);
}
else
{
lmc.add(new MethodConstraint("O", "DIU", Relation.EXTENDS));
lmc.add(new MethodConstraint("N", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("DIU", "N", Relation.EXTENDS));
lmc.add(new MethodConstraint("SY", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH Nm(TPH O)", lmc);
}
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass(className);
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
return new TestResultSet();
}
}

View File

@@ -0,0 +1,126 @@
package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TestMutualRecursion {
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
private static ClassLoader loader;
private static Class<?> classToTest;
private static Object instanceOfClass;
private static String className;
@BeforeClass
public static void resetNamesOfTypePlaceholder() {
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
}
@Test
public void TestMutualRecursion1() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
className = "TestMutualRecursion";
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+className+".jav"));
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS));
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
Set<MethodConstraint> lmc;
lmc = new HashSet<>();
lmc.add(new MethodConstraint("P", "Q", Relation.EXTENDS));
lmc.add(new MethodConstraint("Q", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH ALid(TPH P)", lmc);
lmc = new HashSet<>();
lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("Z", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH ALm(TPH ALTPH Z)", lmc);
lmc = new HashSet<>();
lmc.add(new MethodConstraint("AG", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("AH", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH ALmain(TPH AGTPH AH)", lmc);
FamilyOfGeneratedGenerics fogg = compiler.fogg;
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass(className);
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@Test
public void TestMutualRecursionWithField() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
className = "TestMutualRecursionWithField";
execute(new File(rootDirectory+className+".jav"));
}
@Test
public void TestMutualRecursionWithField2() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
className = "TestMutualRecursionWithField2";
execute(new File(rootDirectory+className+".jav"));
}
@Test
public void TestMutualRecursionWithField3() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
className = "TestMutualRecursionWithField3";
execute(new File(rootDirectory+className+".jav"));
}
private static class TestResultSet{
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass(className);
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
return new TestResultSet();
}
}

View File

@@ -0,0 +1,79 @@
package insertGenerics;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TestReturnVar {
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
@BeforeClass
public static void resetNamesOfTypePlaceholder() {
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
}
@Test
public void ggFinder() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"TestReturnVar.jav"));
}
private static class TestResultSet{
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
}
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
//compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles);
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
System.out.println(ASTTypePrinter.print(sf));
System.out.println(ASTPrinter.print(sf));
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
assert results.size()>0;
Set<String> insertedTypes = new HashSet<>();
for(ResultSet resultSet : results){
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
assert result.size()>0;
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
for(TypeInsert tip : result){
insertedTypes.add(tip.insert(content));
}
}
for(String s : insertedTypes){
System.out.println(s);
}
}
return new TestResultSet();
}
static String readFile(String path, Charset encoding)
throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}
}

View File

@@ -0,0 +1,79 @@
package insertGenerics;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TestSecondLineOfClassConstraints {
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
@BeforeClass
public static void resetNamesOfTypePlaceholder() {
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
}
@Test
public void ggFinder() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"TestSecondLineOfClassConstraints.jav"));
}
private static class TestResultSet{
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
}
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
//compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles);
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
System.out.println(ASTTypePrinter.print(sf));
System.out.println(ASTPrinter.print(sf));
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
assert results.size()>0;
Set<String> insertedTypes = new HashSet<>();
for(ResultSet resultSet : results){
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
assert result.size()>0;
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
for(TypeInsert tip : result){
insertedTypes.add(tip.insert(content));
}
}
for(String s : insertedTypes){
System.out.println(s);
}
}
return new TestResultSet();
}
static String readFile(String path, Charset encoding)
throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}
}

View File

@@ -0,0 +1,154 @@
package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TestTPHsAndGenerics {
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
private static ClassLoader loader;
private static Class<?> classToTest;
private static Object instanceOfClass;
private static String className = "TestTPHsAndGenerics";
@BeforeClass
public static void resetNamesOfTypePlaceholder() {
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
}
@Test
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
execute(new File(rootDirectory+className+".jav"));
}
private static class TestResultSet{
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
FamilyOfGeneratedGenerics fogg = compiler.fogg;
Set<MethodConstraint> lmc;
lmc = new HashSet<>();
if (fogg.allConstraints.contains((new MethodConstraint("DZP", "ETW", Relation.EXTENDS)))) {
classConstraintsTest.add(new ClassConstraint("UD", "DZP", Relation.EXTENDS));
classConstraintsTest.add(new ClassConstraint("DZP", "ETW", Relation.EXTENDS));
classConstraintsTest.add(new ClassConstraint("ETW", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS));
lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS));
//lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS));
lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc);
lmc = new HashSet<>();
lmc.add(new MethodConstraint("V", "UD", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH ETWid2(TPH V)", lmc);
lmc = new HashSet<>();
lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("AI", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc);
} else {
if (fogg.allConstraints.contains((new MethodConstraint("DZP", "U", Relation.EXTENDS)))) {
classConstraintsTest.add(new ClassConstraint("ETW", "DZP", Relation.EXTENDS));
classConstraintsTest.add(new ClassConstraint("DZP", "U", Relation.EXTENDS));
classConstraintsTest.add(new ClassConstraint("U", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS));
lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS));
//lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS));
lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc);
lmc = new HashSet<>();
lmc.add(new MethodConstraint("V", "ETW", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH Uid2(TPH V)", lmc);
lmc = new HashSet<>();
lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("AI", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc);
} else {
if (fogg.allConstraints.contains((new MethodConstraint("EIM", "FEA", Relation.EXTENDS)))) {
classConstraintsTest.add(new ClassConstraint("VK", "EIM", Relation.EXTENDS));
classConstraintsTest.add(new ClassConstraint("EIM", "FEA", Relation.EXTENDS));
classConstraintsTest.add(new ClassConstraint("FEA", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("AI", "AE", Relation.EXTENDS));
lmc.add(new MethodConstraint("AD", "AI", Relation.EXTENDS));
//lmc.add(new MethodConstraint("AB", "AM", Relation.EXTENDS));
lmc.add(new MethodConstraint("AE", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("AB", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH ABm(TPH ABTPH AD)", lmc);
lmc = new HashSet<>();
lmc.add(new MethodConstraint("V", "VK", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH FEAid2(TPH V)", lmc);
lmc = new HashSet<>();
lmc.add(new MethodConstraint("AM", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("AI", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH AIm2(TPH AMTPH AI)", lmc);
}
}
}
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
/*
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass(className);
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
*/
return new TestResultSet();
}
}

View File

@@ -0,0 +1,79 @@
package insertGenerics;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TestTPHsAndGenerics2 {
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
@BeforeClass
public static void resetNamesOfTypePlaceholder() {
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
}
@Test
public void ggFinder() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"TestTPHSAndGenerics2.jav"));
}
private static class TestResultSet{
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
}
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
//compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles);
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
System.out.println(ASTTypePrinter.print(sf));
System.out.println(ASTPrinter.print(sf));
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
assert results.size()>0;
Set<String> insertedTypes = new HashSet<>();
for(ResultSet resultSet : results){
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
assert result.size()>0;
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
for(TypeInsert tip : result){
insertedTypes.add(tip.insert(content));
}
}
for(String s : insertedTypes){
System.out.println(s);
}
}
return new TestResultSet();
}
static String readFile(String path, Charset encoding)
throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}
}

View File

@@ -0,0 +1,99 @@
package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TestThreeArgs {
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
private static ClassLoader loader;
private static Class<?> classToTest;
private static Object instanceOfClass;
private static String className = "TestThreeArgs";
@BeforeClass
public static void resetNamesOfTypePlaceholder() {
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
}
@Test
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
execute(new File(rootDirectory+className+".jav"));
}
private static class TestResultSet{
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS));
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
Set<MethodConstraint> lmc;
lmc = new HashSet<>();
lmc.add(new MethodConstraint("P", "AF", Relation.EXTENDS));
lmc.add(new MethodConstraint("Q", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("AF", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH AFid(TPH P)", lmc);
lmc = new HashSet<>();
lmc.add(new MethodConstraint("AF", "W", Relation.EXTENDS));
lmc.add(new MethodConstraint("AB", "P", Relation.EXTENDS));
lmc.add(new MethodConstraint("P", "AF", Relation.EXTENDS));
lmc.add(new MethodConstraint("AC", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("W", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH Wm(TPH WTPH ABTPH AC)", lmc);
FamilyOfGeneratedGenerics fogg = compiler.fogg;
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass(className);
//liefert Fehler, da Variable "a" nicht initialisiert ist.
//instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
return new TestResultSet();
}
}

View File

@@ -21,8 +21,8 @@ public class TestTransitiveClosure {
@Test @Test
public void genericTest() { public void genericTest() {
List<TPHConstraint> testCons = FamilyOfGeneratedGenerics.buildTransitiveClosure(fillList()); //List<TPHConstraint> testCons = FamilyOfGeneratedGenerics.buildTransitiveClosure(fillList());
System.out.println(testCons); //System.out.println(testCons);
} }
} }

View File

@@ -0,0 +1,111 @@
package insertGenerics;
import static org.junit.Assert.*;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TestTwoArgs {
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
private static ClassLoader loader;
private static Class<?> classToTest;
private static Object instanceOfClass;
private static String className = "TestTwoArgs";
@BeforeClass
public static void resetNamesOfTypePlaceholder() {
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
}
@Test
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
execute(new File(rootDirectory+className+".jav"));
}
private static class TestResultSet{
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
classConstraintsTest.add(new ClassConstraint("AP", "Z", Relation.EXTENDS));
classConstraintsTest.add(new ClassConstraint("Z", "P", Relation.EXTENDS));
classConstraintsTest.add(new ClassConstraint("P", "AL", Relation.EXTENDS));
classConstraintsTest.add(new ClassConstraint("AL", "AF", Relation.EXTENDS));
classConstraintsTest.add(new ClassConstraint("AF", "java/lang/Object", Relation.EXTENDS));
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
Set<MethodConstraint> lmc;
lmc = new HashSet<>();
lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS));
lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH ALid(TPH P)", lmc);
lmc = new HashSet<>();
lmc.add(new MethodConstraint("AL", "AF", Relation.EXTENDS));
lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS));
lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS));
lmc.add(new MethodConstraint("AF", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH AFm(TPH AFTPH Z)", lmc);
lmc = new HashSet<>();
lmc.add(new MethodConstraint("T", "AP", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH APsetA(TPH T)", lmc);
lmc = new HashSet<>();
lmc.add(new MethodConstraint("AG", "P", Relation.EXTENDS));
lmc.add(new MethodConstraint("AH", "T", Relation.EXTENDS));
lmc.add(new MethodConstraint("T", "AP", Relation.EXTENDS));
lmc.add(new MethodConstraint("AL", "AF", Relation.EXTENDS));
lmc.add(new MethodConstraint("P", "AL", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH AFmain(TPH AGTPH AH)", lmc);
FamilyOfGeneratedGenerics fogg = compiler.fogg;
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass(className);
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
return new TestResultSet();
}
}

View File

@@ -0,0 +1,105 @@
package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TestTwoArgs2 {
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
private static ClassLoader loader;
private static Class<?> classToTest;
private static Object instanceOfClass;
private static String className = "TestTwoArgs2";
@BeforeClass
public static void resetNamesOfTypePlaceholder() {
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
}
@Test
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
execute(new File(rootDirectory+className+".jav"));
}
private static class TestResultSet{
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS));
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
Set<MethodConstraint> lmc;
lmc = new HashSet<>();
lmc.add(new MethodConstraint("AG", "AA", Relation.EXTENDS));
lmc.add(new MethodConstraint("U", "P", Relation.EXTENDS));
lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS));
lmc.add(new MethodConstraint("AA", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH AAm(TPH AATPH U)", lmc);
lmc = new HashSet<>();
lmc.add(new MethodConstraint("AB", "P", Relation.EXTENDS));
lmc.add(new MethodConstraint("AC", "U", Relation.EXTENDS));
lmc.add(new MethodConstraint("AB", "AA", Relation.EXTENDS));
lmc.add(new MethodConstraint("AA", "U", Relation.EXTENDS));
lmc.add(new MethodConstraint("AG", "AA", Relation.EXTENDS));
lmc.add(new MethodConstraint("U", "AA", Relation.EXTENDS));
lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH AAmain(TPH ABTPH AC)", lmc);
lmc = new HashSet<>();
lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS));
lmc.add(new MethodConstraint("AG", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH AGid(TPH P)", lmc);
FamilyOfGeneratedGenerics fogg = compiler.fogg;
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass(className);
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
return new TestResultSet();
}
}

View File

@@ -0,0 +1,95 @@
package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TestTwoCalls {
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
private static ClassLoader loader;
private static Class<?> classToTest;
private static Object instanceOfClass;
private static String className = "TestTwoCalls";
@BeforeClass
public static void resetNamesOfTypePlaceholder() {
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
}
@Test
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
execute(new File(rootDirectory+className+".jav"));
}
private static class TestResultSet{
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
Set<MethodConstraint> lmc;
lmc = new HashSet<>();
lmc.add(new MethodConstraint("O", "R", Relation.EXTENDS));
lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH Rid(TPH O)", lmc);
lmc = new HashSet<>();
lmc.add(new MethodConstraint("T", "O", Relation.EXTENDS));
lmc.add(new MethodConstraint("O", "R", Relation.EXTENDS));
lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("S", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH Rmain(TPH STPH T)", lmc);
FamilyOfGeneratedGenerics fogg = compiler.fogg;
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass(className);
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
return new TestResultSet();
}
}

View File

@@ -0,0 +1,92 @@
package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TestVector {
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
private static ClassLoader loader;
private static Class<?> classToTest;
private static Object instanceOfClass;
private static String className = "TestVector";
@BeforeClass
public static void resetNamesOfTypePlaceholder() {
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
}
@Test
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
execute(new File(rootDirectory+className+".jav"));
}
private static class TestResultSet{
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
Set<MethodConstraint> lmc;
lmc = new HashSet<>();
lmc.add(new MethodConstraint("T", "W", Relation.EXTENDS));
lmc.add(new MethodConstraint("W", "ZU", Relation.EXTENDS));
lmc.add(new MethodConstraint("ZU", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("voidm(java/util/Vectorjava/util/Vector)", lmc);
lmc = new HashSet<>();
lmc.add(new MethodConstraint("W", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH Wid(TPH W)", lmc);
FamilyOfGeneratedGenerics fogg = compiler.fogg;
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
assertEquals(expectedClassCons, computedClassCons);
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass(className);
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
return new TestResultSet();
}
}

View File

@@ -0,0 +1,92 @@
package insertGenerics;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TestVectorArg {
private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
private String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
private static ClassLoader loader;
private static Class<?> classToTest;
private static Object instanceOfClass;
private static String className = "TestVectorArg";
@BeforeClass
public static void resetNamesOfTypePlaceholder() {
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
}
@Test
public void ggFinder() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
execute(new File(rootDirectory+className+".jav"));
}
private static class TestResultSet{
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
List<ClassConstraint> classConstraintsTest = new ArrayList<>();
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionTest = new HashMap<>();
Set<MethodConstraint> lmc;
lmc = new HashSet<>();
lmc.add(new MethodConstraint("T", "W", Relation.EXTENDS));
lmc.add(new MethodConstraint("W", "ZU", Relation.EXTENDS));
lmc.add(new MethodConstraint("ZU", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("voidm(java/util/Vectorjava/util/Vector)", lmc);
lmc = new HashSet<>();
lmc.add(new MethodConstraint("W", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH Wid(TPH W)", lmc);
FamilyOfGeneratedGenerics fogg = compiler.fogg;
Set<ClassConstraint> computedClassCons = new HashSet<>(fogg.classConstraints);
Set<ClassConstraint> expectedClassCons = new HashSet<>(classConstraintsTest);
//assertEquals(expectedClassCons, computedClassCons);
HashMap<String, Set<MethodConstraint>> methodConstraintsWithPositionComputed = new HashMap<>();
fogg.methodConstraintsWithPosition.forEach((s, l) -> methodConstraintsWithPositionComputed.put(s,new HashSet<>(l)));
//assertEquals(methodConstraintsWithPositionTest, methodConstraintsWithPositionComputed);
compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles);
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass(className);
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
return new TestResultSet();
}
}

View File

@@ -0,0 +1,79 @@
package insertGenerics;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TestVoidMeth {
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
@BeforeClass
public static void resetNamesOfTypePlaceholder() {
de.dhbwstuttgart.syntaxtree.factory.NameGenerator.reset();
}
@Test
public void ggFinder() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"TestVoidMeth.jav"));
}
private static class TestResultSet{
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
}
List<ResultSet> results = compiler.typeInference();
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
//compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles);
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
System.out.println(ASTTypePrinter.print(sf));
System.out.println(ASTPrinter.print(sf));
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
assert results.size()>0;
Set<String> insertedTypes = new HashSet<>();
for(ResultSet resultSet : results){
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results, simplifyResultsForAllSourceFiles);
assert result.size()>0;
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
for(TypeInsert tip : result){
insertedTypes.add(tip.insert(content));
}
}
for(String s : insertedTypes){
System.out.println(s);
}
}
return new TestResultSet();
}
static String readFile(String path, Charset encoding)
throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}
}

View File

@@ -1,62 +0,0 @@
package typeinference;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSetBuilder;
import de.dhbwstuttgart.typeinference.constraints.OderConstraint;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import org.junit.Test;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class ConstraintSetTests {
@Test
public void cartesianProductTestSingleConstraint(){
ConstraintSetBuilder builder = new ConstraintSetBuilder();
builder.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()))));
List<Set<Pair>> result = builder.build().cartesianProductParallel().collect(Collectors.toList());
assert result.size() == 1;
}
@Test
public void cartesianProductTestSingleOderConstraint(){
ConstraintSetBuilder builder = new ConstraintSetBuilder();
builder.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()), Set.of(generatePair()))));
List<Set<Pair>> result = builder.build().cartesianProductParallel().collect(Collectors.toList());
assert result.size() == 2;
}
@Test
public void cartesianProductTestTwoOderConstraint(){
ConstraintSetBuilder builder = new ConstraintSetBuilder();
builder.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()), Set.of(generatePair()))));
builder.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()), Set.of(generatePair()))));
List<Set<Pair>> result = builder.build().cartesianProductParallel().collect(Collectors.toList());
assert result.size() == 4;
}
@Test
public void cartesianProductTestThreeOderConstraint(){
ConstraintSetBuilder builder = new ConstraintSetBuilder();
builder.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()), Set.of(generatePair()))));
builder.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()), Set.of(generatePair()))));
builder.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()))));
List<Set<Pair>> result = builder.build().cartesianProductParallel().collect(Collectors.toList());
assert result.size() == 4;
ConstraintSetBuilder builder2 = new ConstraintSetBuilder();
builder2.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()), Set.of(generatePair()))));
builder2.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()), Set.of(generatePair()))));
builder2.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()), Set.of(generatePair()))));
List<Set<Pair>> result2 = builder2.build().cartesianProductParallel().collect(Collectors.toList());
assert result2.stream().map( a -> a.stream().map(p -> p.TA1.toString()).reduce("", (x, y)-> x+" "+y)).collect(Collectors.toSet()).size() == 8;
assert result2.size() == 8;
}
public Pair generatePair(){
return new Pair(TypePlaceholder.fresh(new NullToken()), TypePlaceholder.fresh(new NullToken()));
}
}

View File

@@ -1,62 +0,0 @@
package typeinference;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSetBuilder;
import de.dhbwstuttgart.typeinference.constraints.OderConstraint;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import org.junit.Test;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class UnifyConstraintSetTests {
@Test
public void cartesianProductTestSingleConstraint(){
ConstraintSetBuilder builder = new ConstraintSetBuilder();
builder.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()))));
List<Set<Pair>> result = builder.build().cartesianProductParallel().collect(Collectors.toList());
assert result.size() == 1;
}
@Test
public void cartesianProductTestSingleOderConstraint(){
ConstraintSetBuilder builder = new ConstraintSetBuilder();
builder.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()), Set.of(generatePair()))));
List<Set<Pair>> result = builder.build().cartesianProductParallel().collect(Collectors.toList());
assert result.size() == 2;
}
@Test
public void cartesianProductTestTwoOderConstraint(){
ConstraintSetBuilder builder = new ConstraintSetBuilder();
builder.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()), Set.of(generatePair()))));
builder.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()), Set.of(generatePair()))));
List<Set<Pair>> result = builder.build().cartesianProductParallel().collect(Collectors.toList());
assert result.size() == 4;
}
@Test
public void cartesianProductTestThreeOderConstraint(){
ConstraintSetBuilder builder = new ConstraintSetBuilder();
builder.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()), Set.of(generatePair()))));
builder.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()), Set.of(generatePair()))));
builder.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()))));
List<Set<Pair>> result = builder.build().cartesianProductParallel().collect(Collectors.toList());
assert result.size() == 4;
ConstraintSetBuilder builder2 = new ConstraintSetBuilder();
builder2.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()), Set.of(generatePair()))));
builder2.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()), Set.of(generatePair()))));
builder2.addOderConstraint(new OderConstraint(Set.of(Set.of(generatePair()), Set.of(generatePair()))));
List<Set<Pair>> result2 = builder2.build().cartesianProductParallel().collect(Collectors.toList());
assert result2.stream().map( a -> a.stream().map(p -> p.TA1.toString()).reduce("", (x, y)-> x+" "+y)).collect(Collectors.toSet()).size() == 8;
assert result2.size() == 8;
}
public Pair generatePair(){
return new Pair(TypePlaceholder.fresh(new NullToken()), TypePlaceholder.fresh(new NullToken()));
}
}

View File

@@ -1,4 +0,0 @@
package unify;
public class RuleSetTest {
}

View File

@@ -1,47 +0,0 @@
package unify;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.unify2.TypeUnify;
import de.dhbwstuttgart.unify2.model.UnifyConstraintSet;
import de.dhbwstuttgart.unify2.model.UnifyOderConstraint;
import org.junit.Test;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
public class TypeUnifyTest {
@Test
public void emptyInput(){
UnifyConstraintSet empty = new UnifyConstraintSet(new HashSet<>());
TypeUnify.unifyOrConstraints(empty, emptyFC());
}
@Test
public void singleOrConstraintOnlyTPHs(){
Set<UnifyPair> pairs = Set.of(new UnifyPair(PlaceholderType.freshPlaceholder(), PlaceholderType.freshPlaceholder(), PairOperator.EQUALSDOT));
UnifyOderConstraint orConstraint = new UnifyOderConstraint(Set.of(pairs));
UnifyConstraintSet input = new UnifyConstraintSet(Set.of(orConstraint));
Optional<Set<UnifyPair>> res = TypeUnify.unifyOrConstraints(input, emptyFC());
assert res.isPresent();
}
@Test
public void unifyTest1(){
PlaceholderType tph1 = PlaceholderType.freshPlaceholder();
PlaceholderType tph2 = PlaceholderType.freshPlaceholder();
UnifyPair p1 = new UnifyPair(tph1, tph2, PairOperator.SMALLERDOT);
Set<UnifyPair> pairs = Set.of(p1);
UnifyOderConstraint orConstraint = new UnifyOderConstraint(Set.of(pairs));
UnifyConstraintSet input = new UnifyConstraintSet(Set.of(orConstraint));
Optional<Set<UnifyPair>> res = TypeUnify.unifyOrConstraints(input, emptyFC());
assert res.isPresent();
}
private FiniteClosure emptyFC(){
return new FiniteClosure(new HashSet<>(), null);
}
}

View File

@@ -1,11 +0,0 @@
class Cycle{
<A> A und(A a, A b){
return a;
}
m(a){
return und(m(m(a)), a);
}
}

View File

@@ -1,5 +0,0 @@
class Twice{
m(x, f){
return f.apply(f.apply(x));
}
}

View File

@@ -3,7 +3,7 @@ import java.lang.Integer;
public class Fac { public class Fac {
getFac(java.lang.Integer n){ getFac(n){
var res = 1; var res = 1;
var i = 1; var i = 1;
while(i<=n) { while(i<=n) {

View File

@@ -0,0 +1,2 @@
/generatedSC/
/generatedBC/

View File

@@ -0,0 +1,31 @@
import java.util.ArrayList;
import java.util.List;
import java.lang.String;
class TestClassWildcardsFields
{
private List<String> field1;
//private int counter;
public TestClassWildcards () {
//field1 = new ArrayList<>();
//counter = 0;
}
/**
* Working method for Java
* @param param1
* @return
*/
public List<String> test (List<String> param1) {
List<String> localVar = field1;
field1 = param1;
//counter++;
return localVar;
}
public void foo() {
}
}

View File

@@ -0,0 +1,13 @@
import java.lang.String;
import java.lang.Object;
import java.util.Map;
import java.lang.Integer;
class TestClassWildcardsMap
{
public Map<Integer, Object> test(Map<Integer, String> input){
Map<Integer, Object> listOfObjects = input;
return listOfObjects;
}
}

Some files were not shown because too many files have changed in this diff Show More