-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
text highlighting was added to the plugin.
- Loading branch information
Showing
11 changed files
with
290 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
28 changes: 28 additions & 0 deletions
28
...cruise.umple.eclipse.plugin/src/org/cruise/umple/eclipse/plugin/editors/ColorManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.cruise.umple.eclipse.plugin.editors; | ||
|
||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
|
||
import org.eclipse.swt.graphics.Color; | ||
import org.eclipse.swt.graphics.RGB; | ||
import org.eclipse.swt.widgets.Display; | ||
|
||
public class ColorManager { | ||
|
||
protected Map fColorTable = new HashMap(10); | ||
|
||
public void dispose() { | ||
Iterator e = fColorTable.values().iterator(); | ||
while (e.hasNext()) | ||
((Color) e.next()).dispose(); | ||
} | ||
public Color getColor(RGB rgb) { | ||
Color color = (Color) fColorTable.get(rgb); | ||
if (color == null) { | ||
color = new Color(Display.getCurrent(), rgb); | ||
fColorTable.put(rgb, color); | ||
} | ||
return color; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
....umple.eclipse.plugin/src/org/cruise/umple/eclipse/plugin/editors/IUMPColorConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.cruise.umple.eclipse.plugin.editors; | ||
|
||
import org.eclipse.swt.graphics.RGB; | ||
|
||
public interface IUMPColorConstants { | ||
RGB UMP_COMMENT = new RGB(0, 128, 0); | ||
RGB STRING = new RGB(0, 0, 255); | ||
RGB KEYWOED = new RGB(128, 0, 0); | ||
|
||
RGB DEFAULT = new RGB(0, 0, 0); | ||
} |
13 changes: 13 additions & 0 deletions
13
org.cruise.umple.eclipse.plugin/src/org/cruise/umple/eclipse/plugin/editors/Parser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.cruise.umple.eclipse.plugin.editors; | ||
|
||
public class Parser { | ||
public static final String[] KEYWORDS = { | ||
"class","trait","interface","association","associationClass","namespace", | ||
"use","isA","const","lazy","settable","internal","autounique","defaulted", | ||
"after","before","--","->","<-","<@>-","-<@>","sorted","return", | ||
"entry","do","exit","queued","pooled","||","active", | ||
"singleton","immutable","trace"}; | ||
public static final String[] KEYWORDS_TYPES = {"String","Boolean","Integer","Double","Float","void","Date","Time"}; | ||
public static final String[] KEYWORDS_VISIBILITY = {"public","private","protected"}; | ||
public static final String[] KEYWORDS_LANGUAGES = {"Java","Php","Cpp","Ruby"}; | ||
} |
53 changes: 53 additions & 0 deletions
53
...se.umple.eclipse.plugin/src/org/cruise/umple/eclipse/plugin/editors/UMPConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.cruise.umple.eclipse.plugin.editors; | ||
|
||
import org.eclipse.jface.text.IDocument; | ||
import org.eclipse.jface.text.ITextDoubleClickStrategy; | ||
import org.eclipse.jface.text.TextAttribute; | ||
import org.eclipse.jface.text.presentation.IPresentationReconciler; | ||
import org.eclipse.jface.text.presentation.PresentationReconciler; | ||
import org.eclipse.jface.text.rules.DefaultDamagerRepairer; | ||
import org.eclipse.jface.text.rules.Token; | ||
import org.eclipse.jface.text.source.ISourceViewer; | ||
import org.eclipse.jface.text.source.SourceViewerConfiguration; | ||
|
||
public class UMPConfiguration extends SourceViewerConfiguration { | ||
private UMPDoubleClickStrategy doubleClickStrategy; | ||
private UMPScanner scanner; | ||
private ColorManager colorManager; | ||
|
||
public UMPConfiguration(ColorManager colorManager) { | ||
this.colorManager = colorManager; | ||
} | ||
|
||
@Override | ||
public ITextDoubleClickStrategy getDoubleClickStrategy( | ||
ISourceViewer sourceViewer, | ||
String contentType) { | ||
if (doubleClickStrategy == null) | ||
doubleClickStrategy = new UMPDoubleClickStrategy(); | ||
return doubleClickStrategy; | ||
} | ||
|
||
protected UMPScanner getXMLScanner() { | ||
if (scanner == null) { | ||
scanner = new UMPScanner(colorManager); | ||
scanner.setDefaultReturnToken( | ||
new Token( | ||
new TextAttribute( | ||
colorManager.getColor(IUMPColorConstants.DEFAULT)))); | ||
} | ||
return scanner; | ||
} | ||
|
||
@Override | ||
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { | ||
PresentationReconciler reconciler = new PresentationReconciler(); | ||
|
||
DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getXMLScanner()); | ||
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); | ||
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); | ||
|
||
return reconciler; | ||
} | ||
|
||
} |
113 changes: 113 additions & 0 deletions
113
...le.eclipse.plugin/src/org/cruise/umple/eclipse/plugin/editors/UMPDoubleClickStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package org.cruise.umple.eclipse.plugin.editors; | ||
|
||
import org.eclipse.jface.text.*; | ||
|
||
public class UMPDoubleClickStrategy implements ITextDoubleClickStrategy { | ||
protected ITextViewer fText; | ||
|
||
@Override | ||
public void doubleClicked(ITextViewer part) { | ||
int pos = part.getSelectedRange().x; | ||
|
||
if (pos < 0) | ||
return; | ||
|
||
fText = part; | ||
|
||
if (!selectComment(pos)) { | ||
selectWord(pos); | ||
} | ||
} | ||
protected boolean selectComment(int caretPos) { | ||
IDocument doc = fText.getDocument(); | ||
int startPos, endPos; | ||
|
||
try { | ||
int pos = caretPos; | ||
char c = ' '; | ||
|
||
while (pos >= 0) { | ||
c = doc.getChar(pos); | ||
if (c == '\\') { | ||
pos -= 2; | ||
continue; | ||
} | ||
if (c == Character.LINE_SEPARATOR || c == '\"') | ||
break; | ||
--pos; | ||
} | ||
|
||
if (c != '\"') | ||
return false; | ||
|
||
startPos = pos; | ||
|
||
pos = caretPos; | ||
int length = doc.getLength(); | ||
c = ' '; | ||
|
||
while (pos < length) { | ||
c = doc.getChar(pos); | ||
if (c == Character.LINE_SEPARATOR || c == '\"') | ||
break; | ||
++pos; | ||
} | ||
if (c != '\"') | ||
return false; | ||
|
||
endPos = pos; | ||
|
||
int offset = startPos + 1; | ||
int len = endPos - offset; | ||
fText.setSelectedRange(offset, len); | ||
return true; | ||
} catch (BadLocationException x) { | ||
} | ||
|
||
return false; | ||
} | ||
protected boolean selectWord(int caretPos) { | ||
|
||
IDocument doc = fText.getDocument(); | ||
int startPos, endPos; | ||
|
||
try { | ||
|
||
int pos = caretPos; | ||
char c; | ||
|
||
while (pos >= 0) { | ||
c = doc.getChar(pos); | ||
if (!Character.isJavaIdentifierPart(c)) | ||
break; | ||
--pos; | ||
} | ||
|
||
startPos = pos; | ||
|
||
pos = caretPos; | ||
int length = doc.getLength(); | ||
|
||
while (pos < length) { | ||
c = doc.getChar(pos); | ||
if (!Character.isJavaIdentifierPart(c)) | ||
break; | ||
++pos; | ||
} | ||
|
||
endPos = pos; | ||
selectRange(startPos, endPos); | ||
return true; | ||
|
||
} catch (BadLocationException x) { | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private void selectRange(int startPos, int stopPos) { | ||
int offset = startPos + 1; | ||
int length = stopPos - offset; | ||
fText.setSelectedRange(offset, length); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
org.cruise.umple.eclipse.plugin/src/org/cruise/umple/eclipse/plugin/editors/UMPScanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.cruise.umple.eclipse.plugin.editors; | ||
|
||
import org.eclipse.jface.text.rules.*; | ||
import org.eclipse.jface.text.*; | ||
|
||
public class UMPScanner extends RuleBasedScanner { | ||
|
||
public UMPScanner(ColorManager manager) { | ||
|
||
WordRule rule = new WordRule(new IWordDetector() { | ||
public boolean isWordStart(char c) { | ||
return Character.isJavaIdentifierStart(c); | ||
} | ||
public boolean isWordPart(char c) { | ||
return Character.isJavaIdentifierPart(c); | ||
} | ||
}); | ||
|
||
IToken keyword = new Token(new TextAttribute(manager.getColor(IUMPColorConstants.KEYWOED), null, 1)); | ||
IToken comment = new Token(new TextAttribute(manager.getColor(IUMPColorConstants.UMP_COMMENT))); | ||
IToken string = new Token(new TextAttribute(manager.getColor(IUMPColorConstants.STRING))); | ||
|
||
//add tokens for each reserved word | ||
for (int n = 0; n < Parser.KEYWORDS.length; n++) { | ||
rule.addWord(Parser.KEYWORDS[n], keyword); | ||
} | ||
for (int n = 0; n < Parser.KEYWORDS_TYPES.length; n++) { | ||
rule.addWord(Parser.KEYWORDS_TYPES[n], keyword); | ||
} | ||
for (int n = 0; n < Parser.KEYWORDS_VISIBILITY.length; n++) { | ||
rule.addWord(Parser.KEYWORDS_VISIBILITY[n], keyword); | ||
} | ||
for (int n = 0; n < Parser.KEYWORDS_LANGUAGES.length; n++) { | ||
rule.addWord(Parser.KEYWORDS_LANGUAGES[n], keyword); | ||
} | ||
|
||
|
||
IRule[] rules = new IRule[5]; | ||
rules[0] = rule; | ||
rules[1] = new MultiLineRule("/*", "*/", comment); | ||
rules[2] = new SingleLineRule("//","", comment); | ||
rules[3] = new SingleLineRule("\"","\"", string); | ||
|
||
// Add generic whitespace rule. | ||
rules[4] = new WhitespaceRule(new UMPWhitespaceDetector()); | ||
setRules(rules); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ple.eclipse.plugin/src/org/cruise/umple/eclipse/plugin/editors/UMPWhitespaceDetector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.cruise.umple.eclipse.plugin.editors; | ||
|
||
import org.eclipse.jface.text.rules.IWhitespaceDetector; | ||
|
||
public class UMPWhitespaceDetector implements IWhitespaceDetector { | ||
|
||
@Override | ||
public boolean isWhitespace(char c) { | ||
return (c == ' ' || c == '\t' || c == '\n' || c == '\r'); | ||
} | ||
} |