[SCM] Lisaac eclipse plugin branch, master, updated. 8459b9d7d5632cbb57d46d46886df728db9b4c79
Damien Bouvarel
dams.bouvarel at wanadoo.fr
Sat Apr 18 11:22:31 UTC 2009
The following commit has been merged in the master branch:
commit 58a19f58052066eb37c4c505ec9778be65efc6c7
Author: Damien Bouvarel <dams.bouvarel at wanadoo.fr>
Date: Sat Apr 18 02:26:35 2009 +0200
Variable Hyperlink + improve hover presentation
diff --git a/src/org/eclipse/lisaac/editors/AbstractLisaacEditor.java b/src/org/eclipse/lisaac/editors/AbstractLisaacEditor.java
index 30930e5..5773014 100644
--- a/src/org/eclipse/lisaac/editors/AbstractLisaacEditor.java
+++ b/src/org/eclipse/lisaac/editors/AbstractLisaacEditor.java
@@ -1,9 +1,12 @@
package org.eclipse.lisaac.editors;
import java.util.ListResourceBundle;
+import java.util.Timer;
+import java.util.TimerTask;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.action.Action;
@@ -32,19 +35,30 @@ public class AbstractLisaacEditor extends TextEditor {
/** the outline view. */
private LisaacOutlineView outlineView;
+ private boolean refreshDone;
+
public AbstractLisaacEditor() {
super();
colorManager = new ColorManager(LisaacPlugin.getDefault().getPreferenceStore());
-
+
setSourceViewerConfiguration(new LisaacConfiguration(colorManager,this));
setDocumentProvider(new LisaacDocumentProvider());
-
+
IPreferenceStore store = LisaacPlugin.getDefault().getPreferenceStore();
setPreferenceStore(store);
-
+
// wide caret
store.setDefault(PREFERENCE_USE_CUSTOM_CARETS, true);
store.setDefault(PREFERENCE_WIDE_CARET, true);
+ refreshDone = false;
+ }
+
+ protected void handleCursorPositionChanged() {
+ super.handleCursorPositionChanged();
+ if (! refreshDone) {
+ refreshPresentation();
+ refreshDone = true;
+ }
}
public IDocument getDocument() {
@@ -104,7 +118,10 @@ public class AbstractLisaacEditor extends TextEditor {
* Redraw whole text presentation of the editor
*/
public void refreshPresentation() {
- refreshPresentation(0, getDocument().getLength());
+ IDocument document = getDocument();
+ if (document != null) {
+ refreshPresentation(0, document.getLength());
+ }
}
/**
* Redraw region of text presentation of the editor
@@ -151,7 +168,6 @@ public class AbstractLisaacEditor extends TextEditor {
if (outlineView == null) {
outlineView = new LisaacOutlineView(getDocumentProvider(), this);
}
-
return outlineView;
} else {
return super.getAdapter(required);
diff --git a/src/org/eclipse/lisaac/editors/HoverPresenter.java b/src/org/eclipse/lisaac/editors/HoverPresenter.java
new file mode 100644
index 0000000..3b5c970
--- /dev/null
+++ b/src/org/eclipse/lisaac/editors/HoverPresenter.java
@@ -0,0 +1,116 @@
+package org.eclipse.lisaac.editors;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Drawable;
+import org.eclipse.swt.widgets.Display;
+
+import org.eclipse.jface.text.DefaultInformationControl;
+import org.eclipse.jface.text.TextPresentation;
+
+
+/**
+ * Format Lisaac hover text.
+ */
+public class HoverPresenter implements DefaultInformationControl.IInformationPresenter, DefaultInformationControl.IInformationPresenterExtension {
+
+ private static final int NONE = 0;
+ private static final int BOLD = 1;
+ private static final int ITALIC = 2;
+ private static final int GRAY = 3;
+
+ protected ColorManager colorManager;
+
+ public HoverPresenter(ColorManager colorManager) {
+ this.colorManager = colorManager;
+ }
+
+ /*
+ * @see IHoverInformationPresenterExtension#updatePresentation(Drawable drawable, String, TextPresentation, int, int)
+ * @since 3.2
+ */
+ public String updatePresentation(Drawable drawable, String hoverInfo,
+ TextPresentation presentation, int maxWidth, int maxHeight) {
+
+ if (hoverInfo == null)
+ return null;
+
+ StringBuffer buffer= new StringBuffer();
+
+ int style = NONE;
+ int startOffset = 0;
+
+ int len = hoverInfo.length();
+ int i = 0;
+ int derive = 0;
+
+ while (i < len) {
+ char c = hoverInfo.charAt(i);
+
+ if (c == '<' && i < len-3) {
+ if (hoverInfo.charAt(i+1) == '/') {
+ // end of style
+
+ c = Character.toLowerCase(hoverInfo.charAt(i+2));
+ if (hoverInfo.charAt(i+3) == '>') {
+ switch(style) {
+ case BOLD:
+ presentation.addStyleRange(new StyleRange(
+ startOffset - derive, i - startOffset, null, null, SWT.BOLD));
+ break;
+ case ITALIC:
+ presentation.addStyleRange(new StyleRange(
+ startOffset - derive, i - startOffset, null, null, SWT.ITALIC));
+ break;
+ case GRAY:
+ Color gray = colorManager.getColor(ILisaacColor.GRAY);
+ presentation.addStyleRange(new StyleRange(
+ startOffset - derive, i - startOffset, gray, null, SWT.NONE));
+ break;
+ }
+ i += 3;
+ derive += 4;
+ }
+ style = NONE;
+ } else {
+ c = Character.toLowerCase(hoverInfo.charAt(i+1));
+ startOffset = i+3;
+ switch(c) {
+ case 'b':
+ style = BOLD;
+ break;
+ case 'i':
+ style = ITALIC;
+ break;
+ case 'g':
+ style = GRAY;
+ break;
+ }
+ c = hoverInfo.charAt(i+2);
+ if (c != '>') {
+ buffer.append(c);
+ style = NONE;
+ }
+ i += 2;
+ derive += 3;
+ }
+ } else {
+ buffer.append(c);
+ }
+ i++;
+ }
+ return buffer.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.text.DefaultInformationControl.IInformationPresenter#updatePresentation(org.eclipse.swt.widgets.Display, java.lang.String, org.eclipse.jface.text.TextPresentation, int, int)
+ * @deprecated
+ */
+ public String updatePresentation(Display display, String hoverInfo, TextPresentation presentation, int maxWidth, int maxHeight) {
+ return updatePresentation((Drawable)display, hoverInfo, presentation, maxWidth, maxHeight);
+ }
+}
+
diff --git a/src/org/eclipse/lisaac/editors/ILisaacColor.java b/src/org/eclipse/lisaac/editors/ILisaacColor.java
index 0ff798e..814fdf0 100644
--- a/src/org/eclipse/lisaac/editors/ILisaacColor.java
+++ b/src/org/eclipse/lisaac/editors/ILisaacColor.java
@@ -19,6 +19,8 @@ public interface ILisaacColor {
RGB UNDEFINED = new RGB(0, 0, 255);
RGB DEFAULT = new RGB(0, 0, 0);
+ RGB GRAY = new RGB(128, 128, 128);
+
String PREF_COMMENT = "comment_color";
String PREF_PROTOTYPE = "prototype_color";
String PREF_PROTOTYPE_STYLE = "prototype_style_color";
diff --git a/src/org/eclipse/lisaac/editors/LisaacConfiguration.java b/src/org/eclipse/lisaac/editors/LisaacConfiguration.java
index 205b4ba..ed0ddff 100644
--- a/src/org/eclipse/lisaac/editors/LisaacConfiguration.java
+++ b/src/org/eclipse/lisaac/editors/LisaacConfiguration.java
@@ -84,7 +84,7 @@ public class LisaacConfiguration extends SourceViewerConfiguration {
IProject project = editor.getProject();
LisaacModel model = LisaacModel.getModel(project);
- textHover = new LisaacTextHover(model, editor.getFileName());
+ textHover = new LisaacTextHover(model, editor.getFileName(), colorManager);
}
return textHover;
}
diff --git a/src/org/eclipse/lisaac/editors/LisaacEditor.java b/src/org/eclipse/lisaac/editors/LisaacEditor.java
index b165549..6ea91e5 100644
--- a/src/org/eclipse/lisaac/editors/LisaacEditor.java
+++ b/src/org/eclipse/lisaac/editors/LisaacEditor.java
@@ -1,6 +1,5 @@
package org.eclipse.lisaac.editors;
-
/**
* Main class for the Lisaac editor
* @author Damien Bouvarel
diff --git a/src/org/eclipse/lisaac/editors/LisaacTextHover.java b/src/org/eclipse/lisaac/editors/LisaacTextHover.java
index 0cd7d85..79fc5ac 100644
--- a/src/org/eclipse/lisaac/editors/LisaacTextHover.java
+++ b/src/org/eclipse/lisaac/editors/LisaacTextHover.java
@@ -14,6 +14,7 @@ import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region;
import org.eclipse.lisaac.model.LisaacCompletionParser;
import org.eclipse.lisaac.model.LisaacModel;
+import org.eclipse.lisaac.model.items.IVariable;
import org.eclipse.lisaac.model.items.Prototype;
import org.eclipse.lisaac.model.items.Slot;
import org.eclipse.swt.widgets.Shell;
@@ -22,11 +23,13 @@ public class LisaacTextHover implements ITextHover, ITextHoverExtension {
protected LisaacModel model;
protected String filename;
+ protected ColorManager colorManager;
- public LisaacTextHover(LisaacModel model, String filename) {
+ public LisaacTextHover(LisaacModel model, String filename, ColorManager colorManager) {
super();
this.model = model;
this.filename = filename;
+ this.colorManager = colorManager;
}
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
@@ -37,7 +40,7 @@ public class LisaacTextHover implements ITextHover, ITextHoverExtension {
Prototype prototype = LisaacCompletionParser.findPrototype(text, model);
if (prototype != null) {
- return "<I>Prototype : </I> "+prototype.getHoverInformation();
+ return "<I>Prototype</I> : "+prototype.getHoverInformation();
}
} else if (LisaacScanner.isIdentifier(text)) {
// get slot info
@@ -46,7 +49,13 @@ public class LisaacTextHover implements ITextHover, ITextHoverExtension {
if (prototype != null) {
Slot slot = prototype.getSlotFromKeyword(text, prototype.openParser(), hoverRegion.getOffset());
if (slot != null) {
- return "<I>Slot : </I> "+slot.getHoverInformation();
+ return "<I>Slot</I> : <b>"+slot.getHoverInformation()+"</b> <g>- "+slot.getPrototype().getName()+"</g>";
+ } else {
+ slot = prototype.getSlot(hoverRegion.getOffset());
+ IVariable variable = slot.getVariable(text, hoverRegion.getOffset());
+ if (variable != null) {
+ return variable.getHoverInformation();
+ }
}
}
}
@@ -72,7 +81,7 @@ public class LisaacTextHover implements ITextHover, ITextHoverExtension {
public IInformationControlCreator getHoverControlCreator() {
return new IInformationControlCreator() {
public IInformationControl createInformationControl(Shell parent) {
- return new DefaultInformationControl(parent, "", new HTMLTextPresenter());
+ return new DefaultInformationControl(parent, "Lisaac", new HoverPresenter(colorManager));
}
};
}
diff --git a/src/org/eclipse/lisaac/editors/PrototypeHyperLink.java b/src/org/eclipse/lisaac/editors/PrototypeHyperLink.java
index af1080f..0bbc821 100644
--- a/src/org/eclipse/lisaac/editors/PrototypeHyperLink.java
+++ b/src/org/eclipse/lisaac/editors/PrototypeHyperLink.java
@@ -11,6 +11,8 @@ import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.lisaac.LisaacPlugin;
import org.eclipse.lisaac.model.LisaacModel;
+import org.eclipse.lisaac.model.Position;
+import org.eclipse.lisaac.model.items.IVariable;
import org.eclipse.lisaac.model.items.Prototype;
import org.eclipse.lisaac.model.items.Slot;
import org.eclipse.ui.IEditorPart;
@@ -63,7 +65,8 @@ public class PrototypeHyperLink implements IHyperlink {
boolean createLink=false;
Prototype prototype;
Slot slot = null;
-
+ Position position = null;
+
LisaacModel model = LisaacModel.getModel(project);
// Slot Hyperlink
@@ -76,11 +79,26 @@ public class PrototypeHyperLink implements IHyperlink {
if (slot != null) {
// slot hyperlink
prototype = slot.getPrototype();
+ position = slot.getPosition();
} else {
- // prototype hyperlink
- prototype = model.getPrototype(fPrototypeString);
+
+ // variable hyperlink
+ slot = prototype.getSlot(fRegion.getOffset());
+ IVariable variable = slot.getVariable(fPrototypeString, fRegion.getOffset());
+ if (variable != null) {
+ Position p = variable.getPosition();
+ int len = fPrototypeString.length();
+ if (p.length > 0) {
+ len = p.length;
+ }
+ position = new Position(0, 0, p.offset-len, len);
+ } else {
+
+ // prototype hyperlink
+ prototype = model.getPrototype(fPrototypeString);
+ }
}
-
+
if (prototype != null) {
prototypePath = prototype.getFileName();
} else {
@@ -91,7 +109,7 @@ public class PrototypeHyperLink implements IHyperlink {
final IProject p = project;
final String filename = prototypePath;
final boolean link = createLink;
- final Slot selectSlot = slot;
+ final Position selectPosition = position;
part.getSite().getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
@@ -118,10 +136,10 @@ public class PrototypeHyperLink implements IHyperlink {
file.createLink(location, IResource.NONE, null);
}
IDE.openEditor(page, file);
- if (selectSlot != null) {
+ if (selectPosition != null) {
IWorkbenchPart part = w.getPartService().getActivePart();
if (part instanceof LisaacEditor) {
- ((LisaacEditor)part).selectAndReveal(selectSlot.getPosition().offset, selectSlot.getPosition().length);
+ ((LisaacEditor)part).selectAndReveal(selectPosition.offset, selectPosition.length);
}
}
if (link) {
diff --git a/src/org/eclipse/lisaac/model/LisaacCompletionParser.java b/src/org/eclipse/lisaac/model/LisaacCompletionParser.java
index 419978a..215e53b 100644
--- a/src/org/eclipse/lisaac/model/LisaacCompletionParser.java
+++ b/src/org/eclipse/lisaac/model/LisaacCompletionParser.java
@@ -162,6 +162,9 @@ public class LisaacCompletionParser extends LisaacParser {
if (model == null) {
return null;
}
+ if (project == null) {
+ project = model.getProject();
+ }
Prototype prototype = model.getPrototype(prototypeName);
if (prototype != null) {
// prototype is already cached
diff --git a/src/org/eclipse/lisaac/model/LisaacModel.java b/src/org/eclipse/lisaac/model/LisaacModel.java
index 87f8545..600ba3a 100644
--- a/src/org/eclipse/lisaac/model/LisaacModel.java
+++ b/src/org/eclipse/lisaac/model/LisaacModel.java
@@ -8,6 +8,9 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.lisaac.LisaacPlugin;
import org.eclipse.lisaac.builder.LisaacBuilder;
import org.eclipse.lisaac.builder.ILisaacErrorHandler;
@@ -16,6 +19,7 @@ import org.eclipse.lisaac.editors.LisaacEditor;
import org.eclipse.lisaac.model.items.Prototype;
import org.eclipse.lisaac.model.lip.LIP;
import org.eclipse.ui.IPartService;
+import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
@@ -107,7 +111,7 @@ public class LisaacModel implements ILisaacModel{
// refresh editor coloring
IWorkbenchWindow w = LisaacPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
- IWorkbenchPart part = w.getPartService().getActivePart();
+ IWorkbenchPart part = w.getPartService().getActivePart();
if (part instanceof AbstractLisaacEditor) {
((AbstractLisaacEditor)part).refreshPresentation();
}
diff --git a/src/org/eclipse/lisaac/model/LisaacParser.java b/src/org/eclipse/lisaac/model/LisaacParser.java
index 85b74f0..8bcdd14 100644
--- a/src/org/eclipse/lisaac/model/LisaacParser.java
+++ b/src/org/eclipse/lisaac/model/LisaacParser.java
@@ -424,10 +424,12 @@ public class LisaacParser extends AbstractLisaacParser {
//++ | '(' LOCAL ')'
public IArgument readLocArg(boolean mute, boolean selfFirst) {
IArgument result=null;
-
+
if ((selfFirst && readThisKeyword(ILisaacModel.variable_self)) ||
(! selfFirst && readIdentifier())) {
+ int startPos = position;
+
//Position pos = getPosition();
String n = new String(lastString);
if (readCharacter(':') && lastCharacter() != '=') {
@@ -443,7 +445,9 @@ public class LisaacParser extends AbstractLisaacParser {
{tb ?= t; tb = NULL})) {
reporter.syntaxError("Type `SELF' is needed.", getPosition());
}*/
- result = new ITMArgument(n, t);
+ Position p = getPosition();
+ p.offset = startPos;
+ result = new ITMArgument(n, t, p);
} else {
if (! mute) {
reporter.warning("Added ':' is needed.", getPosition());
@@ -468,18 +472,25 @@ public class LisaacParser extends AbstractLisaacParser {
private IArgument readLocalArg(boolean m, boolean s) {
IArgument result=null;
boolean mute = m;
-
+ int startPos;
+
+ int firstPos = position;
+
if ((s && readThisKeyword(ILisaacModel.variable_self)) ||
readIdentifier()) {
List<String> name = new ArrayList<String>();
List<ITypeMono> type = new ArrayList<ITypeMono>();
int beg = 0;
-
+
+
do {
if (name.size() != 0 && !readIdentifier() && !mute) {
reporter.syntaxError("Incorrect argument identifier.", getPosition());
return null;
}
+
+ startPos = position;
+
name.add(lastString);
if (readCharacter(':') && lastCharacter() != '=') {
mute = false;
@@ -511,13 +522,16 @@ public class LisaacParser extends AbstractLisaacParser {
if (name.size() == 1) {
// Single Argument.
- result = new ITMArgument(name.get(0), type.get(0));
+ Position p = new Position(0,0,startPos, 0);
+
+ result = new ITMArgument(name.get(0), type.get(0), p);
+
// free arrays
} else {
// Vector Arguments.
// alias arrays...
TypeMulti tm = new TypeMulti(type.toArray(new ITypeMono[type.size()]));
- result = new ITMArgs(name.toArray(new String[name.size()]), tm);
+ result = new ITMArgs(name.toArray(new String[name.size()]), tm, getPosition(position - firstPos));
}
}
}
@@ -1093,7 +1107,7 @@ public class LisaacParser extends AbstractLisaacParser {
reporter.syntaxError("Incorrect identifier.", getPosition());
return null;
}
- ITMLocal loc = new ITMLocal(new String(lastString));
+ ITMLocal loc = new ITMLocal(new String(lastString), getPosition());
result.add(loc);
if (readCharacter(':') && lastCharacter() != '=') {
mute = false;
diff --git a/src/org/eclipse/lisaac/model/items/IArgument.java b/src/org/eclipse/lisaac/model/items/IArgument.java
index 614a81a..60318e7 100644
--- a/src/org/eclipse/lisaac/model/items/IArgument.java
+++ b/src/org/eclipse/lisaac/model/items/IArgument.java
@@ -2,7 +2,7 @@ package org.eclipse.lisaac.model.items;
import org.eclipse.lisaac.model.types.IType;
-public interface IArgument {
+public interface IArgument extends IVariable {
String getName();
diff --git a/src/org/eclipse/lisaac/model/items/ITMArgs.java b/src/org/eclipse/lisaac/model/items/ITMArgs.java
index 9ac2577..cc52714 100644
--- a/src/org/eclipse/lisaac/model/items/ITMArgs.java
+++ b/src/org/eclipse/lisaac/model/items/ITMArgs.java
@@ -1,5 +1,6 @@
package org.eclipse.lisaac.model.items;
+import org.eclipse.lisaac.model.Position;
import org.eclipse.lisaac.model.types.IType;
import org.eclipse.lisaac.model.types.TypeMulti;
@@ -8,9 +9,12 @@ public class ITMArgs implements IArgument {
protected String[] name;
protected TypeMulti type;
- public ITMArgs(String[] name, TypeMulti type) {
+ protected Position position;
+
+ public ITMArgs(String[] name, TypeMulti type, Position position) {
this.name = name;
this.type = type;
+ this.position = position;
}
public String getName() {
@@ -56,9 +60,9 @@ public class ITMArgs implements IArgument {
buffer.append("(");
for (int i=0; i<name.length; i++) {
IType subType = type.getSubType(i);
- buffer.append(name[i]);
- buffer.append(":");
- buffer.append(subType.toString());
+ buffer.append("<b>"+name[i]+"</b>");
+ buffer.append(" : ");
+ buffer.append("<g>"+subType+"</g>");
if (i != name.length-1) {
buffer.append(", ");
@@ -66,5 +70,17 @@ public class ITMArgs implements IArgument {
}
buffer.append(")");
}
+
+ public String getHoverInformation() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("<I>Arguments</I> : ");
+ printIn(buffer);
+
+ return buffer.toString();
+ }
+
+ public Position getPosition() {
+ return position;
+ }
}
\ No newline at end of file
diff --git a/src/org/eclipse/lisaac/model/items/ITMArgument.java b/src/org/eclipse/lisaac/model/items/ITMArgument.java
index 6811bf1..512d5f0 100644
--- a/src/org/eclipse/lisaac/model/items/ITMArgument.java
+++ b/src/org/eclipse/lisaac/model/items/ITMArgument.java
@@ -1,5 +1,6 @@
package org.eclipse.lisaac.model.items;
+import org.eclipse.lisaac.model.Position;
import org.eclipse.lisaac.model.types.IType;
import org.eclipse.lisaac.model.types.ITypeMono;
@@ -8,9 +9,12 @@ public class ITMArgument implements IArgument {
protected String name;
protected ITypeMono type;
- public ITMArgument(String name, ITypeMono type) {
+ protected Position position;
+
+ public ITMArgument(String name, ITypeMono type, Position position) {
this.name = name;
this.type = type;
+ this.position = position;
}
public String getName() {
@@ -30,4 +34,19 @@ public class ITMArgument implements IArgument {
buffer.append(':');
buffer.append(type);
}
+
+ public String getHoverInformation() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("<I>Argument</I> : <b>");
+ buffer.append(name);
+ buffer.append("</b> <g> : ");
+ buffer.append(type.toString());
+ buffer.append("</g>");
+
+ return buffer.toString();
+ }
+
+ public Position getPosition() {
+ return position;
+ }
}
diff --git a/src/org/eclipse/lisaac/model/items/ITMBlock.java b/src/org/eclipse/lisaac/model/items/ITMBlock.java
index 7e58d4a..5713323 100644
--- a/src/org/eclipse/lisaac/model/items/ITMBlock.java
+++ b/src/org/eclipse/lisaac/model/items/ITMBlock.java
@@ -11,7 +11,9 @@ public class ITMBlock implements ICode {
this.list = list;
this.argument = argument;
- slot.addSubList(this);
+ if (slot != null) {
+ slot.addSubList(this);
+ }
}
public IType getType(Slot slot, Prototype prototype) {
diff --git a/src/org/eclipse/lisaac/model/items/ITMList.java b/src/org/eclipse/lisaac/model/items/ITMList.java
index 8039725..092deaa 100644
--- a/src/org/eclipse/lisaac/model/items/ITMList.java
+++ b/src/org/eclipse/lisaac/model/items/ITMList.java
@@ -12,7 +12,9 @@ public class ITMList implements ICode {
public ITMList(Slot slot, int start) {
startOffset = start;
endOffset = startOffset;
- slot.addSubList(this);
+ if (slot != null) {
+ slot.addSubList(this);
+ }
}
public void setEndOffset(int end) {
diff --git a/src/org/eclipse/lisaac/model/items/ITMLocal.java b/src/org/eclipse/lisaac/model/items/ITMLocal.java
index ed305de..7c58a03 100644
--- a/src/org/eclipse/lisaac/model/items/ITMLocal.java
+++ b/src/org/eclipse/lisaac/model/items/ITMLocal.java
@@ -1,29 +1,48 @@
-package org.eclipse.lisaac.model.items;
-
-import org.eclipse.lisaac.model.types.IType;
-import org.eclipse.lisaac.model.types.ITypeMono;
-
-/**
- * Local declaration slot
- */
-public class ITMLocal {
- protected ITypeMono type;
- protected String name;
-
- public ITMLocal(String name) {
- this.name = name;
- }
-
- public ITMLocal(ITypeMono type, String name) {
- this.type = type;
- this.name = name;
- }
-
- public IType getType() {
- return type;
- }
-
- public void setType(ITypeMono type) {
- this.type = type;
- }
-}
+package org.eclipse.lisaac.model.items;
+
+import org.eclipse.lisaac.model.Position;
+import org.eclipse.lisaac.model.types.IType;
+import org.eclipse.lisaac.model.types.ITypeMono;
+
+/**
+ * Local declaration slot
+ */
+public class ITMLocal implements IVariable {
+ protected ITypeMono type;
+ protected String name;
+
+ protected Position position;
+
+ public ITMLocal(String name, Position position) {
+ this.position = position;
+ this.name = name;
+ }
+
+ public ITMLocal(ITypeMono type, String name) {
+ this.type = type;
+ this.name = name;
+ }
+
+ public IType getType() {
+ return type;
+ }
+
+ public void setType(ITypeMono type) {
+ this.type = type;
+ }
+
+ public String getHoverInformation() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("<I>Local</I> : <b>");
+ buffer.append(name);
+ buffer.append("</b> <g> : ");
+ buffer.append(type.toString());
+ buffer.append("</g>");
+
+ return buffer.toString();
+ }
+
+ public Position getPosition() {
+ return position;
+ }
+}
diff --git a/src/org/eclipse/lisaac/model/items/ITMReadArg2.java b/src/org/eclipse/lisaac/model/items/ITMReadArg2.java
index 34d21ef..252b8c1 100644
--- a/src/org/eclipse/lisaac/model/items/ITMReadArg2.java
+++ b/src/org/eclipse/lisaac/model/items/ITMReadArg2.java
@@ -1,8 +1,10 @@
package org.eclipse.lisaac.model.items;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.lisaac.model.ILisaacModel;
import org.eclipse.lisaac.model.LisaacCompletionParser;
import org.eclipse.lisaac.model.types.IType;
+import org.eclipse.lisaac.model.types.TypeSimple;
public class ITMReadArg2 extends ITMRead {
@@ -31,6 +33,11 @@ public class ITMReadArg2 extends ITMRead {
if (operatorSlot != null) {
// return result type of operator.
return operatorSlot.getResultType();
+ } else {
+ if (name.compareTo("__infix_equal") == 0) {
+ // special case for '=' operator (can't be a slot)
+ return TypeSimple.getTypeBoolean();
+ }
}
}
} catch (CoreException e) {
diff --git a/src/org/eclipse/lisaac/model/items/IVariable.java b/src/org/eclipse/lisaac/model/items/IVariable.java
new file mode 100644
index 0000000..e9f6a1d
--- /dev/null
+++ b/src/org/eclipse/lisaac/model/items/IVariable.java
@@ -0,0 +1,9 @@
+package org.eclipse.lisaac.model.items;
+
+import org.eclipse.lisaac.model.Position;
+
+public interface IVariable {
+ String getHoverInformation();
+
+ Position getPosition();
+}
diff --git a/src/org/eclipse/lisaac/model/items/Prototype.java b/src/org/eclipse/lisaac/model/items/Prototype.java
index 3300509..13a2463 100644
--- a/src/org/eclipse/lisaac/model/items/Prototype.java
+++ b/src/org/eclipse/lisaac/model/items/Prototype.java
@@ -7,7 +7,6 @@ import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.lisaac.model.ILisaacModel;
import org.eclipse.lisaac.model.LisaacCompletionParser;
@@ -70,10 +69,11 @@ public class Prototype {
}
public void addHeaderData(String slotName, String data) {
+ String info = "\n<g>"+slotName+"</g> "+data;
if (headerData == null) {
- headerData = "<br>- "+slotName+" := "+data;
+ headerData = info;
} else {
- this.headerData += "<br>- "+slotName+" := "+data;
+ this.headerData += info;
}
}
@@ -276,6 +276,14 @@ public class Prototype {
bracketLevel++;
}
+ // affectation
+ if (c == '=' && source.length() - offset > 2) {
+ if (source.charAt(offset-1) == ':' ||
+ source.charAt(offset-1) == '?') {
+ break;
+ }
+ }
+
// look at indentation
if (c == '\n' && source.length() - offset > 4) {
if (source.charAt(offset+1) == ' ' &&
@@ -341,7 +349,7 @@ public class Prototype {
if (offset > 0) {
LisaacCompletionParser p = new LisaacCompletionParser(source, (LisaacModel)getModel());
receiver = p.readReceiver(offset+1, pointOffset, this);
-
+
offset = pointOffset;
}
} else {
@@ -372,10 +380,10 @@ public class Prototype {
buffer.append(name);
buffer.append("</b>");
if (headerComment != null) {
- buffer.append("<br>"+headerComment);
+ buffer.append("\n"+headerComment);
}
if (headerData != null) {
- buffer.append("<br><br>"+headerData);
+ buffer.append("\n\n"+headerData);
}
return buffer.toString();
}
diff --git a/src/org/eclipse/lisaac/model/items/Slot.java b/src/org/eclipse/lisaac/model/items/Slot.java
index ce4ac7a..8f76d33 100644
--- a/src/org/eclipse/lisaac/model/items/Slot.java
+++ b/src/org/eclipse/lisaac/model/items/Slot.java
@@ -77,8 +77,11 @@ public class Slot {
public Position getPosition() {
return position;
}
-
+
public int keywordCount() {
+ if (keywordList == null) {
+ return 0;
+ }
return keywordList.length;
}
@@ -155,29 +158,45 @@ public class Slot {
}
public boolean hasVariableDefinition(String word, int offset) {
+ return getVariableDefinition(word, offset) != null;
+ }
+
+ public IVariable getVariableDefinition(String word, int offset) {
ITMList list;
-
+
if (subLists != null) {
for (int i=0; i< subLists.size(); i++) {
ICode c = subLists.get(i);
-
+
if (c instanceof ITMList) {
list = (ITMList) c;
- if (list.isInside(offset) && list.hasVariableDefinition(word)) {
+ if (list != null && list.isInside(offset)) {
// list variable
- return true;
+ IVariable var = list.getLocal(word);
+ if (var != null) {
+ return var;
+ }
}
} else if (c instanceof ITMBlock) {
list = ((ITMBlock) c).list;
+ IArgument arg = ((ITMBlock) c).argument;
- if (list.isInside(offset) && ((ITMBlock) c).argument.hasName(word)) {
+ if (list != null && arg != null && list.isInside(offset) && arg.hasName(word)) {
// block argument
- return true;
+ return arg;
}
}
}
}
- return false;
+ return null;
+ }
+
+ public IVariable getVariable(String word, int offset) {
+ IVariable result = getArgument(word);
+ if (result == null) {
+ result = getVariableDefinition(word, offset);
+ }
+ return result;
}
public Prototype getPrototype() {
diff --git a/src/org/eclipse/lisaac/model/types/TypeSimple.java b/src/org/eclipse/lisaac/model/types/TypeSimple.java
index 55987a9..0ba03ee 100644
--- a/src/org/eclipse/lisaac/model/types/TypeSimple.java
+++ b/src/org/eclipse/lisaac/model/types/TypeSimple.java
@@ -1,65 +1,69 @@
-package org.eclipse.lisaac.model.types;
-
-import java.util.HashMap;
-
-import org.eclipse.lisaac.model.ILisaacModel;
-
-public class TypeSimple implements ITypeMono {
-
- private static HashMap<String,TypeSimple> dico;
-
- protected String name;
-
- TypeSimple(String name) {
- this.name = name;
-
- if (dico == null) {
- dico = new HashMap<String,TypeSimple>();
- }
- dico.put(name, this);
- }
- public String getName() {
- return name;
- }
-
- protected static TypeSimple typeNull;
- protected static TypeSimple typeVoid;
- protected static TypeSimple typeSelf;
-
-
- public static void init() {
- typeNull = new TypeSimple(ILisaacModel.variable_null);
- typeVoid = new TypeSimple(ILisaacModel.variable_void);
- typeSelf = new TypeParameter(ILisaacModel.prototype_self);
- }
-
- public static TypeSimple get(String n) {
- TypeSimple result=null;
-
- if (dico == null) {
- dico = new HashMap<String,TypeSimple>();
- }
- result = dico.get(n);
- if (result == null) {
- result = new TypeSimple(n);
- }
- return result;
- }
-
- public static ITypeMono getTypeSelf() {
- return typeSelf;
- }
- public static ITypeMono getTypeVoid() {
- return typeVoid;
- }
- public static ITypeMono getTypeNull() {
- return typeNull;
- }
-
- public String toString() {
- if (this.equals(typeVoid)) {
- return null; // do not print void type
- }
- return name;
- }
-}
+package org.eclipse.lisaac.model.types;
+
+import java.util.HashMap;
+
+import org.eclipse.lisaac.model.ILisaacModel;
+
+public class TypeSimple implements ITypeMono {
+
+ private static HashMap<String,TypeSimple> dico;
+
+ protected String name;
+
+ TypeSimple(String name) {
+ this.name = name;
+
+ if (dico == null) {
+ dico = new HashMap<String,TypeSimple>();
+ }
+ dico.put(name, this);
+ }
+ public String getName() {
+ return name;
+ }
+
+ protected static TypeSimple typeNull;
+ protected static TypeSimple typeVoid;
+ protected static TypeSimple typeSelf;
+ protected static TypeSimple typeBoolean; // for '=' operator
+
+ public static void init() {
+ typeNull = new TypeSimple(ILisaacModel.variable_null);
+ typeVoid = new TypeSimple(ILisaacModel.variable_void);
+ typeSelf = new TypeParameter(ILisaacModel.prototype_self);
+ typeBoolean = new TypeSimple(ILisaacModel.prototype_boolean);
+ }
+
+ public static TypeSimple get(String n) {
+ TypeSimple result=null;
+
+ if (dico == null) {
+ dico = new HashMap<String,TypeSimple>();
+ }
+ result = dico.get(n);
+ if (result == null) {
+ result = new TypeSimple(n);
+ }
+ return result;
+ }
+
+ public static ITypeMono getTypeSelf() {
+ return typeSelf;
+ }
+ public static ITypeMono getTypeVoid() {
+ return typeVoid;
+ }
+ public static ITypeMono getTypeNull() {
+ return typeNull;
+ }
+ public static ITypeMono getTypeBoolean() {
+ return typeBoolean;
+ }
+
+ public String toString() {
+ if (this.equals(typeVoid)) {
+ return null; // do not print void type
+ }
+ return name;
+ }
+}
--
Lisaac eclipse plugin
More information about the Lisaac-commits
mailing list