Started test driven bug fixing for SyntaxTreeGenerator

This commit is contained in:
luca9913 2023-06-07 22:24:16 +02:00
parent bf15ff693e
commit f08744479a
3 changed files with 16 additions and 9 deletions

View File

@ -475,7 +475,7 @@ blockStatement
;
localVariableDeclaration
: variableModifier* (VAR identifier '=' expression | typeType? variableDeclarators)
: variableModifier* (VAR identifier '=' expression | typeType variableDeclarators)
;
identifier

View File

@ -381,8 +381,12 @@ public class StatementGenerator {
type = TypeGenerator.convert(declaration.typeType(), reg, generics);
}
if (Objects.isNull(declaration.variableDeclarators())) {
Token offset = declaration.identifier().getStart();
ret.add(new Assign(new AssignToLocal(new LocalVar(declaration.identifier().getText(), type, offset)), convert(declaration.expression()), offset));
IdentifierContext identifier = declaration.identifier();
Token offset = identifier.getStart();
String name = identifier.getText();
ret.add(new LocalVarDecl(name, type, offset));
this.localVars.put(name, type);
ret.add(new Assign(new AssignToLocal(new LocalVar(name, type, offset)), convert(declaration.expression()), offset));
} else {
ret.addAll(generateLocalVariableAssignments(declaration.variableDeclarators().variableDeclarator(), type));
}
@ -545,9 +549,9 @@ public class StatementGenerator {
}
ArgumentList argumentList = convertArguments(expr.expressionList());
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = argumentList.getArguments().stream().map(x -> (RefTypeOrTPHOrWildcardOrGeneric) TypePlaceholder.fresh(offset)).collect(Collectors.toCollection(ArrayList::new));
MethodCall ret = new MethodCall(TypePlaceholder.fresh(offset), getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(offset), argTypes, offset);
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> signature = argumentList.getArguments().stream().map(x -> (RefTypeOrTPHOrWildcardOrGeneric) TypePlaceholder.fresh(offset)).collect(Collectors.toCollection(ArrayList::new));
signature.add(TypePlaceholder.fresh(offset)); // return type
MethodCall ret = new MethodCall(TypePlaceholder.fresh(offset), getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(offset), signature, offset);
ret.setStatement();
return ret;
}
@ -561,9 +565,9 @@ public class StatementGenerator {
name = expr.SUPER().getText();
}
ArgumentList argumentList = convertArguments(expr.expressionList());
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = argumentList.getArguments().stream().map(x -> (RefTypeOrTPHOrWildcardOrGeneric) TypePlaceholder.fresh(offset)).collect(Collectors.toCollection(ArrayList::new));
MethodCall ret = new MethodCall(TypePlaceholder.fresh(offset), getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(offset), argTypes, offset);
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> signature = argumentList.getArguments().stream().map(x -> (RefTypeOrTPHOrWildcardOrGeneric) TypePlaceholder.fresh(offset)).collect(Collectors.toCollection(ArrayList::new));
signature.add(TypePlaceholder.fresh(offset)); // return type
MethodCall ret = new MethodCall(TypePlaceholder.fresh(offset), getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(offset), signature, offset);
ret.setStatement();
return ret;
}

View File

@ -14,6 +14,9 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
/**
* Unit-Tests für den 'SyntaxTreeGenerator' aus dem Package 'parser' nach Vorbild der Klasse 'TestComplete' aus dem Test-Package 'targetast'
*/
public class TestComplete {
private static HashMap<String, File[]> javFiles = new HashMap<>();