[SCM] Lisaac eclipse plugin branch, master, updated. 5b80ef281036c47f64a4c9daed9a3c74934198e9
Damien Bouvarel
dams.bouvarel at wanadoo.fr
Sat Jun 6 10:42:19 UTC 2009
The following commit has been merged in the master branch:
commit b3004b55a474705483e9385c3d68537148c62918
Author: Damien Bouvarel <dams.bouvarel at wanadoo.fr>
Date: Mon May 25 17:47:00 2009 +0200
keyword completion
diff --git a/icons/keyword.gif b/icons/keyword.gif
new file mode 100644
index 0000000..435d62e
Binary files /dev/null and b/icons/keyword.gif differ
diff --git a/plugin.xml b/plugin.xml
index 04b540c..d7c3f53 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -204,8 +204,20 @@
id="org.eclipse.lisaac.sourcemenu"
label="%menu.label.0">
<groupMarker
+ name="toggle">
+ </groupMarker>
+ <separator
+ name="org.eclipse.lisaac.separator1">
+ </separator>
+ <groupMarker
name="indent">
</groupMarker>
+ <separator
+ name="org.eclipse.lisaac.separator2">
+ </separator>
+ <groupMarker
+ name="generate">
+ </groupMarker>
</menu>
<action
class="org.eclipse.lisaac.actions.IndentAction"
@@ -219,7 +231,7 @@
definitionId="org.eclipse.lisaac.cmd2"
id="org.eclipse.lisaac.generateconstructor"
label="%action.label.1"
- menubarPath="org.eclipse.lisaac.sourcemenu/indent">
+ menubarPath="org.eclipse.lisaac.sourcemenu/generate">
</action>
<menu
id="org.eclipse.lisaac.toolbar"
@@ -240,7 +252,7 @@
definitionId="org.eclipse.lisaac.cmd4"
id="org.eclipse.lisaac.comment1"
label="%action.label.3"
- menubarPath="org.eclipse.lisaac.sourcemenu/indent">
+ menubarPath="org.eclipse.lisaac.sourcemenu/toggle">
</action>
</actionSet>
</extension>
diff --git a/src/org/eclipse/lisaac/editors/AbstractLisaacEditor.java b/src/org/eclipse/lisaac/editors/AbstractLisaacEditor.java
index 20e116b..9f8819a 100644
--- a/src/org/eclipse/lisaac/editors/AbstractLisaacEditor.java
+++ b/src/org/eclipse/lisaac/editors/AbstractLisaacEditor.java
@@ -9,16 +9,25 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.DefaultInformationControl;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IInformationControl;
+import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.ITextViewerExtension2;
import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.source.IOverviewRuler;
import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.IVerticalRuler;
+import org.eclipse.jface.text.source.projection.ProjectionSupport;
+import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.lisaac.LisaacPlugin;
import org.eclipse.lisaac.model.LisaacModel;
import org.eclipse.lisaac.preferences.PreferenceConstants;
import org.eclipse.lisaac.views.LisaacOutlineView;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.editors.text.TextEditor;
@@ -42,6 +51,9 @@ public class AbstractLisaacEditor extends TextEditor {
private boolean refreshDone;
+ private ProjectionSupport fProjectionSupport;
+
+
public AbstractLisaacEditor() {
super();
colorManager = new ColorManager(LisaacPlugin.getDefault().getPreferenceStore());
@@ -60,7 +72,7 @@ public class AbstractLisaacEditor extends TextEditor {
setPreferenceStore(store);
}
-
+
/**
* Returns the preference store to be used by this editor.
* @return the preference store to be used by this editor
@@ -199,6 +211,12 @@ public class AbstractLisaacEditor extends TextEditor {
* @see AbstractTextEditor#getAdapter(java.lang.Class)
*/
public Object getAdapter(Class required) {
+
+ if (fProjectionSupport != null) {
+ Object adapter = fProjectionSupport.getAdapter(getSourceViewer(), required);
+ if (adapter != null)
+ return adapter;
+ }
if (IContentOutlinePage.class.equals(required)) {
if (outlineView == null) {
outlineView = new LisaacOutlineView(getDocumentProvider(), this);
diff --git a/src/org/eclipse/lisaac/editors/LisaacCompletionProcessor.java b/src/org/eclipse/lisaac/editors/LisaacCompletionProcessor.java
index 65b3b5a..d131987 100644
--- a/src/org/eclipse/lisaac/editors/LisaacCompletionProcessor.java
+++ b/src/org/eclipse/lisaac/editors/LisaacCompletionProcessor.java
@@ -58,7 +58,7 @@ public class LisaacCompletionProcessor implements IContentAssistProcessor {
ArrayList<ICompletionProposal> proposals) {
int bracketLevel=0;
//
- // Rewind to '(' '{' ';' '[' ':'
+ // Rewind to '(' '{' ';' '[' ':' '<-'
//
try {
int pos = baseOffset-1;
diff --git a/src/org/eclipse/lisaac/editors/LisaacScanner.java b/src/org/eclipse/lisaac/editors/LisaacScanner.java
index 705dcee..b980577 100644
--- a/src/org/eclipse/lisaac/editors/LisaacScanner.java
+++ b/src/org/eclipse/lisaac/editors/LisaacScanner.java
@@ -2,6 +2,7 @@ package org.eclipse.lisaac.editors;
import org.eclipse.jface.text.*;
import org.eclipse.jface.text.rules.*;
+import org.eclipse.lisaac.model.ILisaacModel;
import org.eclipse.swt.graphics.RGB;
class LisaacWhitespaceDetector implements IWhitespaceDetector {
@@ -61,13 +62,6 @@ class LisaacWordDetector implements IWordDetector {
public class LisaacScanner extends RuleBasedScanner {
private ColorManager manager;
- private static String[] keywords = new String[] { "Section", "Public",
- "Private", "Inherit", "Header", "Insert", "Mapping", "Interrupt",
- "External", "Directory",
- "Expanded", "Strict",
- "Left", "Right",
- "Self",};
-
// Lisaac tokens
private IToken stringToken;
private IToken characterToken;
@@ -126,6 +120,7 @@ public class LisaacScanner extends RuleBasedScanner {
// keywords rule
WordRule wr = new WordRule(new LisaacKeywordDetector(), Token.UNDEFINED);
+ String[] keywords = ILisaacModel.keywords;
for (int i = 0; i < keywords.length; i++) {
wr.addWord(keywords[i], keywordToken);
}
@@ -325,6 +320,10 @@ public class LisaacScanner extends RuleBasedScanner {
return detectKeyword(word, new LisaacWordDetector());
}
+ public static boolean isKeywordIdentifier(String word) {
+ return detectKeyword(word, new LisaacKeywordDetector());
+ }
+
private static boolean detectKeyword(String word, IWordDetector detector) {
int i = 0;
char c;
diff --git a/src/org/eclipse/lisaac/model/AbstractLisaacParser.java b/src/org/eclipse/lisaac/model/AbstractLisaacParser.java
index dcf3965..5b37e28 100644
--- a/src/org/eclipse/lisaac/model/AbstractLisaacParser.java
+++ b/src/org/eclipse/lisaac/model/AbstractLisaacParser.java
@@ -783,6 +783,10 @@ public class AbstractLisaacParser {
private final String operators = "!@#$%^&<|*-+=~/?\\>";
+ public boolean isOperatorSymbol(char c) {
+ return operators.indexOf(c) != -1;
+ }
+
//-- operator -> '!' | '@' | '#' | '$' | '%' | '^' | '&' | '<' | '|'
//-- | '*' | '-' | '+' | '=' | '~' | '/' | '?' | '\' | '>'
public boolean readOperator() {
diff --git a/src/org/eclipse/lisaac/model/ILisaacModel.java b/src/org/eclipse/lisaac/model/ILisaacModel.java
index c333598..fc187f2 100644
--- a/src/org/eclipse/lisaac/model/ILisaacModel.java
+++ b/src/org/eclipse/lisaac/model/ILisaacModel.java
@@ -5,6 +5,13 @@ import org.eclipse.lisaac.model.lip.LIP;
public interface ILisaacModel {
+ final String[] keywords = new String[] { "Section", "Public",
+ "Private", "Inherit", "Header", "Insert", "Mapping", "Interrupt",
+ "External", "Directory",
+ "Expanded", "Strict",
+ "Left", "Right",
+ "Self",};
+
final String inherit_shared = "Shared";
final String inherit_shared_expanded = "Shared Expanded";
final String inherit_nonshared = "Non Shared";
diff --git a/src/org/eclipse/lisaac/model/LisaacCompletionParser.java b/src/org/eclipse/lisaac/model/LisaacCompletionParser.java
index 8ff6b40..015a733 100644
--- a/src/org/eclipse/lisaac/model/LisaacCompletionParser.java
+++ b/src/org/eclipse/lisaac/model/LisaacCompletionParser.java
@@ -14,12 +14,14 @@ import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.lisaac.LisaacPlugin;
import org.eclipse.lisaac.builder.ILisaacErrorHandler;
import org.eclipse.lisaac.editors.LisaacEditor;
+import org.eclipse.lisaac.editors.LisaacScanner;
import org.eclipse.lisaac.model.items.ICode;
import org.eclipse.lisaac.model.items.ITMPrototype;
import org.eclipse.lisaac.model.items.ITMRead;
import org.eclipse.lisaac.model.items.Prototype;
import org.eclipse.lisaac.model.items.Slot;
import org.eclipse.lisaac.model.types.IType;
+import org.eclipse.lisaac.outline.OutlineImages;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
@@ -53,6 +55,24 @@ public class LisaacCompletionParser extends LisaacParser {
currentSlot = currentPrototype.getSlot(startOffset);
endOffset = -1;
+ // keyword match
+ while (readKeyword()) {
+ if (baseOffset != (startOffset+position)) {
+ continue;// not last keyword
+ }
+ String[] keywords = ILisaacModel.keywords;
+ for (int i = 0; i < keywords.length; i++) {
+ if (keywords[i].startsWith(lastString)) {// length(keyword[i]) >= length(lastString)
+ String keywordCompletion = keywords[i].substring(lastString.length());
+ proposals.add(new CompletionProposal(keywordCompletion,
+ baseOffset, 0, keywordCompletion.length(),
+ OutlineImages.KEYWORD, keywords[i], null, ""));
+ }
+ }
+ return;
+ }
+
+ // slot match
ICode code = readExpr();
if (code != null && currentPrototype != null) {
type = code.getType(currentSlot, currentPrototype);
diff --git a/src/org/eclipse/lisaac/model/items/Prototype.java b/src/org/eclipse/lisaac/model/items/Prototype.java
index e1a16e6..c07e11a 100644
--- a/src/org/eclipse/lisaac/model/items/Prototype.java
+++ b/src/org/eclipse/lisaac/model/items/Prototype.java
@@ -43,7 +43,7 @@ public class Prototype {
slotList = new HashMap<String,Slot>();
parentList = new HashMap<String,Slot>();
-
+
if (filename.compareTo(name) == 0) {
this.filename = (filename.toLowerCase()).concat(".li");
}
@@ -253,7 +253,7 @@ public class Prototype {
public Slot getSlotFromKeyword(String keyword, LisaacParser parser, int baseOffset) throws CoreException {
String source = parser.getSource();
- int bracketLevel = 0;
+ int bracketLevel = 0, invBracketLevel = 0;
Prototype receiver = null;
Slot result = null;
char c = 0;
@@ -268,25 +268,39 @@ public class Prototype {
// find beginning of SEND_MSG grammar rule
//
- // Rewind to '(' '{' ';' '[' '.'
+ // Rewind to '(' '{' ';' '[' '.' '<-' 'operator'
c = source.charAt(offset);
- if (c == ';' || c == '.') {
- break;
- }
+
if (c == '(' || c == '{' || c == '[') {
if (bracketLevel == 0) {
break;
}
bracketLevel--;
+ invBracketLevel++;
}
if (c == ')' || c == '}' || c == ']') {
bracketLevel++;
+ invBracketLevel--;
}
-
- // affectation
- if (c == '=' && source.length() - offset > 2) {
- if (source.charAt(offset-1) == ':' ||
- source.charAt(offset-1) == '?') {
+
+ // ok, we're not in nested statements
+ if (bracketLevel == 0 && invBracketLevel == 0) {
+ if (c == ';' || c == '.') {
+ break;
+ }
+
+ // affectation
+ if (c == '=' && source.length() - offset > 2) {
+ if (source.charAt(offset-1) == ':' ||
+ source.charAt(offset-1) == '?') {
+ break;
+ }
+ } else if (c == '-' && source.length() - offset > 2) {
+ if (source.charAt(offset-1) == '<') {
+ break;
+ }
+ }
+ if (parser.isOperatorSymbol(c)) {
break;
}
}
diff --git a/src/org/eclipse/lisaac/outline/OutlineImages.java b/src/org/eclipse/lisaac/outline/OutlineImages.java
index 96708c6..5021a75 100644
--- a/src/org/eclipse/lisaac/outline/OutlineImages.java
+++ b/src/org/eclipse/lisaac/outline/OutlineImages.java
@@ -1,21 +1,23 @@
-package org.eclipse.lisaac.outline;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.lisaac.LisaacPlugin;
-import org.eclipse.swt.graphics.Image;
-
-public class OutlineImages {
- public static final Image PROTOTYPE = getImage("/icons/prototype.gif");
-
- public static final Image PUBLIC_SHARED = getImage("/icons/public-shared.gif");
- public static final Image PRIVATE_SHARED = getImage("/icons/private-shared.gif");
- public static final Image PUBLIC_NONSHARED = getImage("/icons/public-nonshared.gif");
- public static final Image PRIVATE_NONSHARED = getImage("/icons/private-nonshared.gif");
-
- public static final Image BLANK = getImage("/icons/blank.gif");
-
- private static Image getImage(String path) {
- ImageDescriptor descr = LisaacPlugin.getImageDescriptor(path);
- return descr.createImage();
- }
-}
+package org.eclipse.lisaac.outline;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.lisaac.LisaacPlugin;
+import org.eclipse.swt.graphics.Image;
+
+public class OutlineImages {
+ public static final Image PROTOTYPE = getImage("/icons/prototype.gif");
+
+ public static final Image PUBLIC_SHARED = getImage("/icons/public-shared.gif");
+ public static final Image PRIVATE_SHARED = getImage("/icons/private-shared.gif");
+ public static final Image PUBLIC_NONSHARED = getImage("/icons/public-nonshared.gif");
+ public static final Image PRIVATE_NONSHARED = getImage("/icons/private-nonshared.gif");
+
+ public static final Image KEYWORD = getImage("/icons/keyword.gif");
+
+ public static final Image BLANK = getImage("/icons/blank.gif");
+
+ private static Image getImage(String path) {
+ ImageDescriptor descr = LisaacPlugin.getImageDescriptor(path);
+ return descr.createImage();
+ }
+}
--
Lisaac eclipse plugin
More information about the Lisaac-commits
mailing list