bug fix VectorNotObject test

This commit is contained in:
luca9913 2023-06-01 20:59:16 +02:00
parent 52b7040337
commit 30a62a6621
5 changed files with 647 additions and 699 deletions

View File

@ -51,11 +51,10 @@ http://maven.apache.org/maven-v4_0_0.xsd">
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version> <version>3.11.0</version>
<configuration> <configuration>
<compilerArgs>--enable-preview</compilerArgs> <compilerArgs>--enable-preview</compilerArgs>
<source>19</source> <release>20</release>
<target>19</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
@ -112,8 +111,6 @@ http://maven.apache.org/maven-v4_0_0.xsd">
</repository> </repository>
</repositories> </repositories>
<properties> <properties>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
<mainClass>de.dhbwstuttgart.core.ConsoleInterface</mainClass> <mainClass>de.dhbwstuttgart.core.ConsoleInterface</mainClass>
</properties> </properties>
<distributionManagement> <distributionManagement>

File diff suppressed because it is too large Load Diff

View File

@ -122,17 +122,15 @@ public class StatementGenerator {
public ParameterList convert(Java17Parser.FormalParameterListContext formalParameterListContext) { public ParameterList convert(Java17Parser.FormalParameterListContext formalParameterListContext) {
List<FormalParameter> ret = new ArrayList<>(); List<FormalParameter> ret = new ArrayList<>();
List<Java17Parser.FormalParameterContext> fps = new ArrayList<>(); List<Java17Parser.FormalParameterContext> fps = new ArrayList<>();
if (formalParameterListContext == null || formalParameterListContext.lastFormalParameter() == null) if (!Objects.isNull(formalParameterListContext.lastFormalParameter())) {
/*
* Der '...' Operator wird noch nicht unterstützt, da dafür benötigte Typen (List oder Array) nicht vom Typinferenzalgo. verarbeitet werden können
*/
throw new NotImplementedException("Formale Parameter variabler Länge nicht unterstützt.");
}
if (formalParameterListContext.children.size() == 0)
return new ParameterList(ret, new NullToken()); // Dann ist die Parameterliste leer return new ParameterList(ret, new NullToken()); // Dann ist die Parameterliste leer
/*
* Restrukturierung Java17-Grammatik Zeile wird nicht mehr benötigt, da Regel für Parameter-Liste nicht mehr rekursiv ist. "lastFormalParameter" hat kein Kind "formalParameter" mehr.
*
* if(formalParameterListContext.lastFormalParameter().formalParameter() == null) throw new NotImplementedException();
*/
fps = formalParameterListContext.formalParameter(); fps = formalParameterListContext.formalParameter();
for (Java17Parser.FormalParameterContext fp : fps) { for (Java17Parser.FormalParameterContext fp : fps) {
String paramName = SyntaxTreeGenerator.convert(fp.variableDeclaratorId()); String paramName = SyntaxTreeGenerator.convert(fp.variableDeclaratorId());
RefTypeOrTPHOrWildcardOrGeneric type; RefTypeOrTPHOrWildcardOrGeneric type;

View File

@ -206,7 +206,7 @@ public class StatementToTargetExpression implements StatementVisitor {
var returnType = isFunNType ? TargetType.Object : converter.convert(methodCall.signature.get(methodCall.signature.size() - 1)); var returnType = isFunNType ? TargetType.Object : converter.convert(methodCall.signature.get(methodCall.signature.size() - 1));
var receiverName = new JavaClassName(converter.convert(methodCall.receiver.getType()).name()); var receiverName = new JavaClassName(converter.convert(methodCall.receiver.getType()).name());
var argList = methodCall.signature.stream().map(converter::convert).toList(); var argList = methodCall.signature.stream().map(converter::convert).toList();
argList = argList.subList(0, argList.size() - 1); // argList = argList.subList(0, argList.size() - 1);
Method foundMethod = null; Method foundMethod = null;
if (methodCall.receiver instanceof ExpressionReceiver expressionReceiver && expressionReceiver.expr instanceof This) { if (methodCall.receiver instanceof ExpressionReceiver expressionReceiver && expressionReceiver.expr instanceof This) {

View File

@ -206,7 +206,7 @@ public class TestComplete {
vv1.addElement(v3); vv1.addElement(v3);
vv1.addElement(v4); vv1.addElement(v4);
var instanceOfClass_m2 = matrixOP.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1); var instanceOfClass_m2 = matrixOP.getDeclaredConstructor(Vector.class).newInstance(vv1);// Matrix m2 = new Matrix(vv1);
var mul = matrixOP.getField("mul"); var mul = matrixOP.getField("mul");
mul.setAccessible(true); mul.setAccessible(true);
@ -238,10 +238,10 @@ public class TestComplete {
var matrix = classFiles.get("Matrix"); var matrix = classFiles.get("Matrix");
Vector<Vector<Integer>> vv = new Vector<>(); Vector<Vector<Integer>> vv = new Vector<>();
Vector<Integer> v1 = new Vector<> (); Vector<Integer> v1 = new Vector<>();
v1.addElement(2); v1.addElement(2);
v1.addElement(2); v1.addElement(2);
Vector<Integer> v2 = new Vector<> (); Vector<Integer> v2 = new Vector<>();
v2.addElement(3); v2.addElement(3);
v2.addElement(3); v2.addElement(3);
vv.addElement(v1); vv.addElement(v1);
@ -250,10 +250,10 @@ public class TestComplete {
var instanceOfClass_m1 = matrix.getDeclaredConstructor(Vector.class).newInstance(vv); var instanceOfClass_m1 = matrix.getDeclaredConstructor(Vector.class).newInstance(vv);
Vector<Vector<Integer>> vv1 = new Vector<>(); Vector<Vector<Integer>> vv1 = new Vector<>();
Vector<Integer> v3 = new Vector<> (); Vector<Integer> v3 = new Vector<>();
v3.addElement(2); v3.addElement(2);
v3.addElement(2); v3.addElement(2);
Vector<Integer> v4 = new Vector<> (); Vector<Integer> v4 = new Vector<>();
v4.addElement(3); v4.addElement(3);
v4.addElement(3); v4.addElement(3);
vv1.addElement(v3); vv1.addElement(v3);
@ -266,10 +266,10 @@ public class TestComplete {
System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m2.toString() + " = " + result.toString()); System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m2.toString() + " = " + result.toString());
Vector<Vector<Integer>> res = new Vector<>(); Vector<Vector<Integer>> res = new Vector<>();
Vector<Integer> v5 = new Vector<> (); Vector<Integer> v5 = new Vector<>();
v5.addElement(10); v5.addElement(10);
v5.addElement(10); v5.addElement(10);
Vector<Integer> v6 = new Vector<> (); Vector<Integer> v6 = new Vector<>();
v6.addElement(15); v6.addElement(15);
v6.addElement(15); v6.addElement(15);
res.addElement(v5); res.addElement(v5);
@ -324,7 +324,7 @@ public class TestComplete {
var relOps = classFiles.get("RelOps"); var relOps = classFiles.get("RelOps");
var instance = relOps.getDeclaredConstructor().newInstance(); var instance = relOps.getDeclaredConstructor().newInstance();
var m = relOps.getDeclaredMethod("m", Integer.class,Integer.class); var m = relOps.getDeclaredMethod("m", Integer.class, Integer.class);
assertFalse((Boolean) m.invoke(instance, 7, 3)); assertFalse((Boolean) m.invoke(instance, 7, 3));
} }
@ -487,7 +487,6 @@ public class TestComplete {
assertEquals(W, m2.getGenericReturnType()); assertEquals(W, m2.getGenericReturnType());
} }
@Test @Test
public void Tph7Test() throws Exception { public void Tph7Test() throws Exception {
var classFiles = TestCodegen.generateClassFiles("Tph7.jav", new ByteArrayClassLoader()); var classFiles = TestCodegen.generateClassFiles("Tph7.jav", new ByteArrayClassLoader());
@ -497,59 +496,55 @@ public class TestComplete {
// public <N, O> N m(O var1, N var2) // public <N, O> N m(O var1, N var2)
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class); Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
//System.out.println(m.toString()); // System.out.println(m.toString());
//Argumenttypes of the method m // Argumenttypes of the method m
var paraTypes = m.getGenericParameterTypes(); var paraTypes = m.getGenericParameterTypes();
//Typeparameters of the method m // Typeparameters of the method m
var typeParaTypes = m.getTypeParameters(); var typeParaTypes = m.getTypeParameters();
//Typeparameters are extracted from the argumenttypes // Typeparameters are extracted from the argumenttypes
//Conditions for the extracted typeparameters are set // Conditions for the extracted typeparameters are set
//paraTypes[0] = O // paraTypes[0] = O
var boundFstArg = Arrays.stream(typeParaTypes) var boundFstArg = Arrays.stream(typeParaTypes).filter(x -> x.equals(paraTypes[0])).findFirst().get().getBounds();
.filter(x -> x.equals(paraTypes[0])).findFirst().get().getBounds();
//Bound of O has to be Object // Bound of O has to be Object
assertEquals(Object.class, Arrays.stream(boundFstArg).findFirst().get()); assertEquals(Object.class, Arrays.stream(boundFstArg).findFirst().get());
//paraTypes[1] = N // paraTypes[1] = N
var N = Arrays.stream(typeParaTypes) var N = Arrays.stream(typeParaTypes).filter(x -> x.equals(paraTypes[1])).findFirst().get();
.filter(x -> x.equals(paraTypes[1])).findFirst().get();
var boundSndArg = N.getBounds(); var boundSndArg = N.getBounds();
//Bound of H has to be Object // Bound of H has to be Object
assertEquals(Object.class, Arrays.stream(boundSndArg).findFirst().get()); assertEquals(Object.class, Arrays.stream(boundSndArg).findFirst().get());
//N has to be the return type of m // N has to be the return type of m
assertEquals(N, m.getGenericReturnType()); assertEquals(N, m.getGenericReturnType());
//public <DZU> DZU m2(DZU); // public <DZU> DZU m2(DZU);
Method m2 = classToTest.getDeclaredMethod("m2", Object.class); Method m2 = classToTest.getDeclaredMethod("m2", Object.class);
//Argumenttypes of the method m2 // Argumenttypes of the method m2
var paraTypesm2 = m2.getGenericParameterTypes(); var paraTypesm2 = m2.getGenericParameterTypes();
//Typeparameters of the method m2 // Typeparameters of the method m2
var typeParaTypesm2 = m2.getTypeParameters(); var typeParaTypesm2 = m2.getTypeParameters();
//Typeparameters are extracted from the argumenttypes // Typeparameters are extracted from the argumenttypes
//Conditions for the extracted typeparameters are set // Conditions for the extracted typeparameters are set
//paraTypes[0] = DZU // paraTypes[0] = DZU
var fstArgm2 = Arrays.stream(typeParaTypesm2) var fstArgm2 = Arrays.stream(typeParaTypesm2).filter(x -> x.equals(paraTypesm2[0])).findFirst().get();
.filter(x -> x.equals(paraTypesm2[0])).findFirst().get();
//Bound of DZU has to be Object // Bound of DZU has to be Object
assertEquals(Object.class, Arrays.stream(fstArgm2.getBounds()).findFirst().get()); assertEquals(Object.class, Arrays.stream(fstArgm2.getBounds()).findFirst().get());
//DZU has to be the return type of m // DZU has to be the return type of m
assertEquals(fstArgm2, m2.getGenericReturnType()); assertEquals(fstArgm2, m2.getGenericReturnType());
} }
@Test @Test
public void typedIdTest() throws Exception { public void typedIdTest() throws Exception {
var classFiles = generateClassFiles("TypedID.jav", new ByteArrayClassLoader()); var classFiles = generateClassFiles("TypedID.jav", new ByteArrayClassLoader());