Commit 0504db7e authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Improved missing return proposal


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 2f2a4c1b
......@@ -613,10 +613,22 @@ public final class Def_Function extends Definition implements IParameterisedAssi
identifier.getLocation().reportSemanticError(
"The function has a return type, but it does not have any return statement",
new HoverProposal[] {
new HoverProposal("Add return statement...", getLocation().getEndOffset() - 1) {
new HoverProposal("Add missing return statement...", getLocation().getEndOffset() - 1) {
@Override
public void run(IMarker marker) {
insertText("return;\n");
public void run(IMarker marker) {
String retval = "";
switch (getType(timestamp).getTypetypeTtcn3()) {
case TYPE_INTEGER:
retval = "0";
break;
case TYPE_CHARSTRING:
retval = "\"\"";
break;
case TYPE_HEXSTRING:
retval = "00H";
default:
}
insertText("return " + retval + ";\n");
}
}
});
......
......@@ -9,6 +9,7 @@ package org.eclipse.titan.designer.editors.controls;
import org.eclipse.core.resources.IMarker;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.RewriteSessionEditProcessor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.text.edits.InsertEdit;
......@@ -27,6 +28,7 @@ public class HoverProposal extends WorkbenchMarkerResolution {
private IEditorPart editor = null;
private Location location;
private int offset;
private int indent;
public HoverProposal(String label, int offset) {
this.label = label;
......@@ -40,7 +42,7 @@ public class HoverProposal extends WorkbenchMarkerResolution {
@Override
public void run(IMarker marker) {
insertText("return;\n", 0);
}
@Override
......@@ -63,21 +65,41 @@ public class HoverProposal extends WorkbenchMarkerResolution {
public void setEditor(IEditorPart editor) {
this.editor = editor;
countIndent();
}
protected void insertText(String text) {
insertText(text, offset);
}
protected int countIndent() {
IDocument doc = ((TTCN3Editor) editor).getDocument();
int indent = 0;
try {
while (offset > indent && doc.getChar(offset - indent) == '\t') {
indent++;
}
} catch (BadLocationException e) {
}
this.indent = indent;
return indent;
}
protected void insertText(String text, int newOffset) {
if (editor == null) {
return;
}
StringBuilder indentedText = new StringBuilder();
for (int i = 0; i <= indent; i++) {
indentedText.append('\t');
}
indentedText.append(text);
final MultiTextEdit multiEdit = new MultiTextEdit(newOffset, 0);
final RewriteSessionEditProcessor processor = new RewriteSessionEditProcessor(((TTCN3Editor) editor).getDocument(),
multiEdit, TextEdit.UPDATE_REGIONS | TextEdit.CREATE_UNDO);
multiEdit.addChild(new InsertEdit(newOffset, text));
multiEdit.addChild(new InsertEdit(newOffset, indentedText.toString()));
try {
processor.performEdits();
......
......@@ -44,6 +44,6 @@ public class MarkerHoverContent {
}
public int nrOfProposals() {
return proposals.length;
return proposals == null ? 0 : proposals.length;
}
}
......@@ -33,7 +33,6 @@ import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.AST.TTCN3.definitions.IHoverContent;
import org.eclipse.titan.designer.editors.BaseTextHover;
import org.eclipse.titan.designer.editors.IReferenceParser;
import org.eclipse.titan.designer.editors.controls.HoverContentType;
import org.eclipse.titan.designer.editors.controls.HoverProposal;
import org.eclipse.titan.designer.editors.controls.MarkerHoverContent;
import org.eclipse.titan.designer.editors.controls.PeekSource;
......
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