Compare commits

...
Author SHA1 Message Date
Deepinder Kaur 1e027754eb Test: Parser unterscheidet m(...) und m.(...).
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 2m1s
2026-11-25 09:50:58 +01:00
Deepinder Kaur 01719544f3 AST: LazyMethodCall für m.(...) ergänzen
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 1m27s
2026-11-20 09:21:26 +01:00
Deepinder Kaur 9ca2dedcad Parser: Lazy-Methodenaufruf m.(...) erlauben.
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 2m20s
2026-11-20 08:53:23 +01:00
5 changed files with 99 additions and 1 deletions

No files matched your search

@@ -0,0 +1,16 @@
import java.lang.Integer;
public class LazyMethodCallParser {
public m(x) {
return x;
}
public testEager() {
return m(1);
}
public testLazy() {
return m.(1);
}
}
@@ -598,7 +598,10 @@ expressionList
;
methodCall
// eager: m(...)
: identifier '(' expressionList? ')'
// lazy: m.(...)
| identifier '.' '(' expressionList? ')'
| THIS '(' expressionList? ')'
| SUPER '(' expressionList? ')'
;
@@ -734,6 +734,9 @@ public class StatementGenerator {
ret = new SuperCall(argumentList, TypePlaceholder.fresh(offset), signature, offset);
} else if(expr.THIS() != null) {
ret = new ThisCall(argumentList, TypePlaceholder.fresh(offset), signature, offset);
} else if (expr.DOT() != null) {
// Lazy-Aufruf: m.(...)
ret = new LazyMethodCall(TypePlaceholder.fresh(offset), getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(offset), signature, offset);
} else {
ret = new MethodCall(TypePlaceholder.fresh(offset), getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(offset), signature, offset);
}
@@ -753,7 +756,13 @@ public class StatementGenerator {
ArgumentList argumentList = convertArguments(expr.expressionList());
ArrayList<TypePlaceholder> signature = argumentList.getArguments().stream().map(x -> 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);
MethodCall ret;
if (expr.DOT() != null) {
// Lazy-Aufruf: receiver.m.(...)
ret = new LazyMethodCall(TypePlaceholder.fresh(offset), getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(offset), signature, offset);
} else {
ret = new MethodCall(TypePlaceholder.fresh(offset), getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(offset), signature, offset);
}
ret.setStatement();
return ret;
}
@@ -0,0 +1,17 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import org.antlr.v4.runtime.Token;
import java.util.ArrayList;
// Lazy-Methodenaufruf: m.(...)
public class LazyMethodCall extends MethodCall {
public LazyMethodCall(RefTypeOrTPHOrWildcardOrGeneric retType, Receiver receiver, String methodName,
ArgumentList argumentList, RefTypeOrTPHOrWildcardOrGeneric receiverType,
ArrayList<TypePlaceholder> signature, Token offset) {
super(retType, receiver, methodName, argumentList, receiverType, signature, offset);
}
}
@@ -0,0 +1,53 @@
package parser;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.statement.LazyMethodCall;
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
// Prüft: m(...) -> MethodCall, m.(...) -> LazyMethodCall
public class LazyMethodCallParserTest {
@Test
public void eagerAndLazyMethodCallAreDistinguished() throws Exception {
File src = new File("resources/bytecode/javFiles/LazyMethodCallParser.jav");
assertTrue(src.exists(), "Testdatei fehlt: " + src.getAbsolutePath());
JavaTXCompiler compiler = new JavaTXCompiler(src);
compiler.parseAll();
SourceFile sf = compiler.sourceFiles.get(src);
assertNotNull(sf);
List<MethodCall> eagerCalls = new ArrayList<>();
List<LazyMethodCall> lazyCalls = new ArrayList<>();
new AbstractASTWalker() {
@Override
public void visit(MethodCall methodCall) {
if (methodCall instanceof LazyMethodCall lazy) {
lazyCalls.add(lazy);
} else {
eagerCalls.add(methodCall);
}
super.visit(methodCall);
}
}.visit(sf);
assertFalse(eagerCalls.isEmpty(), "Erwartet mindestens einen eager-Aufruf m(...)");
assertFalse(lazyCalls.isEmpty(), "Erwartet mindestens einen Lazy-Aufruf m.(...)");
assertTrue(eagerCalls.stream().anyMatch(c -> c.name.equals("m")),
"Eager-Aufruf m(...) nicht gefunden");
assertTrue(lazyCalls.stream().anyMatch(c -> c.name.equals("m")),
"Lazy-Aufruf m.(...) nicht gefunden");
}
}