protected void internalToJavaExpression(final XExpression obj, final ITreeAppendable appendable) { _toJavaExpression(obj, appendable); }
protected void doInternalToJavaStatement(XExpression obj, ITreeAppendable builder, boolean isReferenced) { _toJavaStatement(obj, builder, isReferenced); }
public ITreeAppendable compile(XExpression obj, ITreeAppendable parentAppendable, /* @Nullable */ JvmTypeReference expectedReturnType, /* @Nullable */ Set<JvmTypeReference> declaredExceptions) { LightweightTypeReference converted = null; if (expectedReturnType != null) { converted = newTypeReferenceOwner(obj).toLightweightTypeReference(expectedReturnType); } return compile(obj, parentAppendable, converted, declaredExceptions); }
public ITreeAppendable compileAsJavaExpression(XExpression obj, ITreeAppendable parentAppendable, JvmTypeReference expectedType) { LightweightTypeReference converted = null; if (expectedType != null) { converted = newTypeReferenceOwner(obj).toLightweightTypeReference(expectedType); } return compileAsJavaExpression(obj, parentAppendable, converted); }
public ITreeAppendable compileAsJavaExpression(XExpression obj, ITreeAppendable parentAppendable, LightweightTypeReference expectedType) { ITreeAppendable appendable = parentAppendable.trace(obj, true); if (expectedType == null) { expectedType = getLightweightReturnType(obj); if (expectedType == null) { expectedType = getLightweightType(obj); final boolean isPrimitiveVoid = isPrimitiveVoid(obj); final boolean earlyExit = isEarlyExit(obj); boolean needsSneakyThrow = needsSneakyThrow(obj, Collections.<JvmTypeReference>emptySet()); boolean needsToBeWrapped = earlyExit || needsSneakyThrow || !canCompileToJavaExpression(obj, appendable); if (needsToBeWrapped) { appendable.openScope(); JvmType procedureOrFunction = null; if (isPrimitiveVoidExpected) { procedureOrFunction = findKnownType(Procedures.Procedure0.class, obj); } else { procedureOrFunction = findKnownType(Functions.Function0.class, obj); internalToJavaStatement(obj, appendable, !isPrimitiveVoidExpected && !isPrimitiveVoid && !earlyExit); if (!isPrimitiveVoidExpected && !earlyExit) { appendable.newLine().append("return "); if (isPrimitiveVoid && !isPrimitiveVoidExpected) { appendDefaultLiteral(appendable, expectedType); } else { internalToJavaExpression(obj, appendable); generateCheckedExceptionHandling(appendable);
final boolean isPrimitiveVoid = isPrimitiveVoid(obj); final boolean earlyExit = isEarlyExit(obj); boolean needsSneakyThrow = needsSneakyThrow(obj, declaredExceptions); if (needsSneakyThrow && isPrimitiveVoidExpected && hasJvmConstructorCall(obj)) { compileWithJvmConstructorCall((XBlockExpression) obj, appendable); return parentAppendable; appendable.newLine().append("try {").increaseIndentation(); internalToJavaStatement(obj, appendable, !isPrimitiveVoidExpected && !isPrimitiveVoid && !earlyExit); if (!isPrimitiveVoidExpected && !earlyExit) { appendable.newLine().append("return "); if (isPrimitiveVoid && !isPrimitiveVoidExpected) { appendDefaultLiteral(appendable, expectedReturnType); } else { internalToConvertedExpression(obj, appendable, expectedReturnType); generateCheckedExceptionHandling(appendable);
protected void declareSyntheticVariable(final XExpression expr, ITreeAppendable b) { declareFreshLocalVariable(expr, b, new Later() { @Override public void exec(ITreeAppendable appendable) { appendable.append(getDefaultValueLiteral(expr)); } }); }
public ITreeAppendable compile(XExpression obj, ITreeAppendable appendable, LightweightTypeReference expectedReturnType) { compile(obj, appendable, expectedReturnType, null); return appendable; }
protected final void internalToJavaStatement(XExpression obj, ITreeAppendable builder, boolean isReferenced) { final ITreeAppendable trace = builder.trace(obj, true); doInternalToJavaStatement(obj, trace, isReferenced); }
protected JvmType findKnownType(Class<?> rawType, Notifier context) { if (rawType.isArray()) { throw new IllegalArgumentException(rawType.getCanonicalName()); } if (rawType.isPrimitive()) { throw new IllegalArgumentException(rawType.getName()); } ResourceSet resourceSet = EcoreUtil2.getResourceSet(context); if (resourceSet == null) { return null; } Class<?> declaringClass = rawType.getDeclaringClass(); if (declaringClass == null) { return findKnownTopLevelType(rawType, resourceSet); } JvmType result = (JvmType) resourceSet.getEObject(URIHelperConstants.OBJECTS_URI.appendSegment(declaringClass.getName()).appendFragment(rawType.getName()), true); return result; }