Skip to content

Commit

Permalink
removed duplication by constructorCallToJavaExpression
Browse files Browse the repository at this point in the history
instead of redefining _toJavaStatement we redefine
constructorCallToJavaExpression and we call it also in other parts
  • Loading branch information
LorenzoBettini committed Jan 2, 2024
1 parent 723d944 commit 74faea2
Showing 1 changed file with 11 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import org.eclipse.xtext.xbase.XbasePackage;
import org.eclipse.xtext.xbase.compiler.GeneratorConfig;
import org.eclipse.xtext.xbase.compiler.IGeneratorConfigProvider;
import org.eclipse.xtext.xbase.compiler.Later;
import org.eclipse.xtext.xbase.compiler.XbaseCompiler;
import org.eclipse.xtext.xbase.compiler.output.ITreeAppendable;
import org.eclipse.xtext.xbase.lib.Extension;
Expand Down Expand Up @@ -433,8 +432,16 @@ protected void _toJavaExpression(AnonymousClass anonymousClass, ITreeAppendable
} else {
XConstructorCall constructorCall = anonymousClass.getConstructorCall();
constructorCallToJavaExpression(constructorCall, b);
JvmDeclaredType declaringType = constructorCall.getConstructor().getDeclaringType();
compileAnonymousClassBody(anonymousClass, declaringType, b);
}
}

@Override
protected void constructorCallToJavaExpression(XConstructorCall expr, ITreeAppendable b) {
super.constructorCallToJavaExpression(expr, b);
if (expr.eContainer() instanceof AnonymousClass) {
JvmConstructor constructor = expr.getConstructor();
JvmDeclaredType declaringType = constructor.getDeclaringType();
compileAnonymousClassBody((AnonymousClass) expr.eContainer(), declaringType, b);
}
}

Expand Down Expand Up @@ -535,38 +542,7 @@ public void _toJavaStatement(final XStringLiteral expr, ITreeAppendable b, boole
protected void _toJavaStatement(final AnonymousClass anonymousClass, ITreeAppendable b, final boolean isReferenced) {
_toJavaStatement(anonymousClass.getConstructorCall(), b, isReferenced);
}

@Override
protected void _toJavaStatement(final XConstructorCall expr, ITreeAppendable b, final boolean isReferenced) {
for (XExpression arg : expr.getArguments()) {
prepareExpression(arg, b);
}

if (!isReferenced) {
b.newLine();
constructorCallToJavaExpression(expr, b);
if (expr.eContainer() instanceof AnonymousClass) {
JvmConstructor constructor = expr.getConstructor();
JvmDeclaredType declaringType = constructor.getDeclaringType();
compileAnonymousClassBody((AnonymousClass) expr.eContainer(), declaringType, b);
}
b.append(";");
} else if (isVariableDeclarationRequired(expr, b, true)) {
Later later = new Later() {
@Override
public void exec(ITreeAppendable appendable) {
constructorCallToJavaExpression(expr, appendable);
if (expr.eContainer() instanceof AnonymousClass) {
JvmConstructor constructor = expr.getConstructor();
JvmDeclaredType declaringType = constructor.getDeclaringType();
compileAnonymousClassBody((AnonymousClass) expr.eContainer(), declaringType, appendable);
}
}
};
declareFreshLocalVariable(expr, b, later);
}
}


@Override
protected boolean internalCanCompileToJavaExpression(XExpression expression, ITreeAppendable appendable) {
if(expression instanceof AnonymousClass) {
Expand Down

0 comments on commit 74faea2

Please sign in to comment.