Commit aed29b83 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Missing function proposal can also guess return type


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent e39c7494
......@@ -609,18 +609,7 @@ public final class Def_Function extends Definition implements IParameterisedAssi
// check the presence of return statements
switch (block.hasReturn(timestamp)) {
case RS_NO:
String retval = "";
switch (getType(timestamp).getTypetypeTtcn3()) {
case TYPE_INTEGER:
retval = "0";
break;
case TYPE_CHARSTRING:
retval = "\"\"";
break;
case TYPE_HEXSTRING:
retval = "00H";
default:
}
String retval = Type.typeToSrcTypeDefault(getType(timestamp).getTypetypeTtcn3());
identifier.getLocation().reportSemanticError(
"The function has a return type, but it does not have any return statement",
new HoverProposal[] {
......
......@@ -29,6 +29,7 @@ import org.eclipse.titan.designer.AST.INamedNode;
import org.eclipse.titan.designer.AST.IReferenceChain;
import org.eclipse.titan.designer.AST.ISubReference;
import org.eclipse.titan.designer.AST.IType;
import org.eclipse.titan.designer.AST.IType.Type_type;
import org.eclipse.titan.designer.AST.Identifier;
import org.eclipse.titan.designer.AST.Identifier.Identifier_type;
import org.eclipse.titan.designer.AST.Location;
......@@ -57,6 +58,7 @@ import org.eclipse.titan.designer.AST.TTCN3.attributes.TitanVersionAttribute;
import org.eclipse.titan.designer.AST.TTCN3.attributes.VersionRequirementAttribute;
import org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath;
import org.eclipse.titan.designer.AST.TTCN3.types.Anytype_Type;
import org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.core.CompilerVersionInformationCollector;
import org.eclipse.titan.designer.core.LoadBalancingUtilities;
......@@ -868,6 +870,7 @@ public final class TTCN3Module extends Module {
final List<ISubReference> subReferences = reference.getSubreferences();;
if (subReferences.size() > 0) {
if (subReferences.get(0) instanceof ParameterisedSubReference) {
boolean isReferenced = false;
StringBuilder propCode = new StringBuilder();
propCode.append("\n\tfunction ");
propCode.append(reference.getDisplayName().substring(0, reference.getDisplayName().length() - 1));
......@@ -882,7 +885,23 @@ public final class TTCN3Module extends Module {
propCode.append(Type.typeToSrcType(inst.getExpressionReturntype(timestamp, null)));
propCode.append(" param" + (i + 1));
}
propCode.append(") {\n\t\t// function body\n\t}\n\n");
propCode.append(")");
Type_type valueType = null;
if (reference.getNameParent() instanceof Referenced_Value) {
Referenced_Value value = (Referenced_Value)reference.getNameParent();
valueType = value.getMyGovernor().getTypetype();
propCode.append(" return ");
propCode.append(Type.typeToSrcType(valueType));
propCode.append(' ');
isReferenced = true;
}
propCode.append("{\n\t\t// function body\n");
if (isReferenced) {
propCode.append("\n\t\treturn ");
propCode.append(Type.typeToSrcTypeDefault(valueType));
propCode.append(";\n");
}
propCode.append("\t}\n\n");
HoverProposal prop = new HoverProposal("Insert missing function prototype...") {
@Override
public void run(IMarker marker) {
......
......@@ -4202,4 +4202,26 @@ public abstract class Type extends Governor implements IType, IIncrementallyUpda
return "";
}
}
/**
* Gets the default value of types for quick fix code insertions
* FIXME add missing types
*
* @param type
* @return
*/
public static String typeToSrcTypeDefault(Type_type type) {
switch (type) {
case TYPE_INTEGER:
return "0";
case TYPE_CHARSTRING:
return "\"\"";
case TYPE_BITSTRING:
return "\"00B\"";
case TYPE_REAL:
return "0.0";
default:
return "";
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment