forked from JavaTX/JavaCompilerCore
Fixed bugs in StatementGenerator regarding constructor generation and field accesses
This commit is contained in:
parent
f08744479a
commit
78ad7bc003
@ -573,12 +573,10 @@ public class StatementGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Receiver getReceiver(ExpressionContext expr) {
|
public Receiver getReceiver(ExpressionContext expr) {
|
||||||
Expression expression;
|
Expression expression = generateLocalOrFieldVarOrClassName(expr.getText(), expr.getStart());
|
||||||
if (expr instanceof PrimaryexpressionContext pc) {
|
/*
|
||||||
expression = convert(pc.primary());
|
* if (expr instanceof PrimaryexpressionContext pc) { expression = convert(pc.primary()); } else { expression = generateLocalOrFieldVarOrClassName(expr.getText(), expr.getStart()); }
|
||||||
} else {
|
*/
|
||||||
expression = generateLocalOrFieldVarOrClassName(expr.getText(), expr.getStart());
|
|
||||||
}
|
|
||||||
return getReceiver(expression);
|
return getReceiver(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -816,7 +814,7 @@ public class StatementGenerator {
|
|||||||
case PrimaryLiteralContext primliteral:
|
case PrimaryLiteralContext primliteral:
|
||||||
return convert(primliteral.literal());
|
return convert(primliteral.literal());
|
||||||
case PrimaryIdentifierContext primidentifier:
|
case PrimaryIdentifierContext primidentifier:
|
||||||
return new LocalVar(primidentifier.getText(), TypePlaceholder.fresh(primidentifier.getStart()), primidentifier.getStart());
|
return generateLocalOrFieldVarOrClassName(primidentifier.getText(), primidentifier.getStart());
|
||||||
case PrimaryClassrefContext primclassref:
|
case PrimaryClassrefContext primclassref:
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
default:
|
default:
|
||||||
|
@ -308,7 +308,12 @@ public class SyntaxTreeGenerator {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MembermethodContext membermethod: {
|
case MembermethodContext membermethod: {
|
||||||
methods.add(convert(membermodifiers, membermethod.method(), name, superClass, generics));
|
Method convertedMethod = convert(membermodifiers, membermethod.method(), name, superClass, generics);
|
||||||
|
if (convertedMethod instanceof Constructor constructor) {
|
||||||
|
constructors.add(constructor);
|
||||||
|
} else {
|
||||||
|
methods.add(convertedMethod);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MemberconstructorContext memberconstructor: {
|
case MemberconstructorContext memberconstructor: {
|
||||||
@ -516,7 +521,11 @@ public class SyntaxTreeGenerator {
|
|||||||
MethodblockContext methodblock = (MethodblockContext) body;
|
MethodblockContext methodblock = (MethodblockContext) body;
|
||||||
block = stmtgen.convert(methodblock.block(), true);
|
block = stmtgen.convert(methodblock.block(), true);
|
||||||
}
|
}
|
||||||
return new Method(modifiers, name, retType, paramlist, block, gtvDeclarations, header.getStart());
|
if (name.equals(parentClass.getClassName())) {
|
||||||
|
return new Constructor(modifiers, name, retType, paramlist, block, gtvDeclarations, methoddeclaration.getStart());
|
||||||
|
} else {
|
||||||
|
return new Method(modifiers, name, retType, paramlist, block, gtvDeclarations, methoddeclaration.getStart());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Constructor convert(int modifiers, Java17Parser.ConstructorContext constructorContext, JavaClassName parentClass, RefType superClass, GenericsRegistry generics) {
|
public Constructor convert(int modifiers, Java17Parser.ConstructorContext constructorContext, JavaClassName parentClass, RefType superClass, GenericsRegistry generics) {
|
||||||
|
5
src/test/java/syntaxtreegenerator/TestNewFeatures.java
Normal file
5
src/test/java/syntaxtreegenerator/TestNewFeatures.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package syntaxtreegenerator;
|
||||||
|
|
||||||
|
public class TestNewFeatures {
|
||||||
|
|
||||||
|
}
|
@ -4,7 +4,7 @@ class Faculty {
|
|||||||
Faculty(){
|
Faculty(){
|
||||||
super(());
|
super(());
|
||||||
}
|
}
|
||||||
TPH DDBK getFact(java.lang.Integer x){
|
TPH DDBK getFact(TPH DDBL x){
|
||||||
return this.fact.apply Signature: [TPH DDBM, TPH DDBN](x);
|
return this.fact.apply Signature: [TPH DDBM, TPH DDBN](x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user