Commit 2f2a4c1b authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Added HoverProposal text insert


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 18a94ee4
......@@ -15,6 +15,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.IMarker;
import org.eclipse.jface.text.templates.Template;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.StyledString.Styler;
......@@ -612,7 +613,12 @@ 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...")
new HoverProposal("Add return statement...", getLocation().getEndOffset() - 1) {
@Override
public void run(IMarker marker) {
insertText("return;\n");
}
}
});
break;
case RS_MAYBE:
......
......@@ -8,17 +8,29 @@
package org.eclipse.titan.designer.editors.controls;
import org.eclipse.core.resources.IMarker;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.RewriteSessionEditProcessor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.text.edits.InsertEdit;
import org.eclipse.text.edits.MultiTextEdit;
import org.eclipse.text.edits.TextEdit;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.designer.AST.Location;
import org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.views.markers.WorkbenchMarkerResolution;
public class HoverProposal extends WorkbenchMarkerResolution {
public static final String PROPOSAL = "proposal";
private String label;
private IEditorPart editor = null;
private Location location;
private int offset;
public HoverProposal(String label) {
public HoverProposal(String label, int offset) {
this.label = label;
this.offset = offset;
}
@Override
......@@ -28,8 +40,7 @@ public class HoverProposal extends WorkbenchMarkerResolution {
@Override
public void run(IMarker marker) {
MessageDialog.openInformation(null, "QuickFix Demo",
"This quick-fix is not yet implemented");
insertText("return;\n", 0);
}
@Override
......@@ -49,4 +60,37 @@ public class HoverProposal extends WorkbenchMarkerResolution {
// TODO Auto-generated method stub
return null;
}
public void setEditor(IEditorPart editor) {
this.editor = editor;
}
protected void insertText(String text) {
insertText(text, offset);
}
protected void insertText(String text, int newOffset) {
if (editor == null) {
return;
}
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));
try {
processor.performEdits();
} catch (BadLocationException e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
public Location getLocation() {
return location;
}
public void setLocation(Location location) {
this.location = location;
}
}
......@@ -176,6 +176,7 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
@Override
public void run() {
prop.run(null);
dispose();
}
};
propAction.setText(prop.getLabel());
......
......@@ -134,7 +134,9 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
if (attr instanceof HoverProposal[]) {
HoverProposal[] propsInMarker = (HoverProposal[])attr;
for (int i = 0; i < propsInMarker.length; i++) {
proposals.add(propsInMarker[i]);
HoverProposal propEntry = propsInMarker[i];
propEntry.setEditor(editor);
proposals.add(propEntry);
}
}
}
......
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