redcar-javamateview 0.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/LICENSE +34 -0
  2. data/README +58 -0
  3. data/Rakefile +94 -0
  4. data/lib/javamateview.rb +41 -0
  5. data/lib/javamateview/example.rb +334 -0
  6. data/lib/javamateview/jar/java-mateview.jar +0 -0
  7. data/lib/javamateview/jcodings.jar +0 -0
  8. data/lib/javamateview/jdom.jar +0 -0
  9. data/lib/javamateview/joni.jar +0 -0
  10. data/spec/onig/match_spec.rb +50 -0
  11. data/spec/parsing/dynamic_parsing_spec.rb +172 -0
  12. data/spec/parsing/static_parsing_spec.rb +476 -0
  13. data/spec/spec_helper.rb +33 -0
  14. data/src/com/redcareditor/mate/Bundle.java +81 -0
  15. data/src/com/redcareditor/mate/DoublePattern.java +89 -0
  16. data/src/com/redcareditor/mate/Grammar.java +129 -0
  17. data/src/com/redcareditor/mate/IAnnotationAreaListener.java +7 -0
  18. data/src/com/redcareditor/mate/IGrammarListener.java +5 -0
  19. data/src/com/redcareditor/mate/IncludePattern.java +10 -0
  20. data/src/com/redcareditor/mate/LineNumberRulerColumn.java +922 -0
  21. data/src/com/redcareditor/mate/Marker.java +22 -0
  22. data/src/com/redcareditor/mate/MateText.java +697 -0
  23. data/src/com/redcareditor/mate/ParseThunk.java +71 -0
  24. data/src/com/redcareditor/mate/Parser.java +627 -0
  25. data/src/com/redcareditor/mate/ParserScheduler.java +237 -0
  26. data/src/com/redcareditor/mate/Pattern.java +152 -0
  27. data/src/com/redcareditor/mate/RangeSet.java +91 -0
  28. data/src/com/redcareditor/mate/Scanner.java +178 -0
  29. data/src/com/redcareditor/mate/Scope.java +534 -0
  30. data/src/com/redcareditor/mate/ScopeMatcher.java +162 -0
  31. data/src/com/redcareditor/mate/SharedTextColors.java +110 -0
  32. data/src/com/redcareditor/mate/SinglePattern.java +20 -0
  33. data/src/com/redcareditor/mate/WhitespaceCharacterPainter.java +395 -0
  34. data/src/com/redcareditor/mate/colouring/Colourer.java +16 -0
  35. data/src/com/redcareditor/mate/colouring/swt/MarginPaintListener.java +62 -0
  36. data/src/com/redcareditor/mate/colouring/swt/SwtColourer.java +501 -0
  37. data/src/com/redcareditor/mate/document/MateDocument.java +15 -0
  38. data/src/com/redcareditor/mate/document/MateTextFactory.java +9 -0
  39. data/src/com/redcareditor/mate/document/MateTextLocation.java +8 -0
  40. data/src/com/redcareditor/mate/document/MateTextLocationComparator.java +17 -0
  41. data/src/com/redcareditor/mate/document/MateTextRange.java +18 -0
  42. data/src/com/redcareditor/mate/document/swt/SwtMateDocument.java +143 -0
  43. data/src/com/redcareditor/mate/document/swt/SwtMateTextLocation.java +88 -0
  44. data/src/com/redcareditor/mate/document/swt/SwtMateTextRange.java +92 -0
  45. data/src/com/redcareditor/mate/document/swt/SwtScopePositionUpdater.java +90 -0
  46. data/src/com/redcareditor/mate/undo/MateTextUndoManager.java +11 -0
  47. data/src/com/redcareditor/mate/undo/swt/SwtMateTextUndoManager.java +166 -0
  48. data/src/com/redcareditor/onig/Match.java +212 -0
  49. data/src/com/redcareditor/onig/NullMatch.java +57 -0
  50. data/src/com/redcareditor/onig/NullRx.java +29 -0
  51. data/src/com/redcareditor/onig/Range.java +45 -0
  52. data/src/com/redcareditor/onig/Rx.java +167 -0
  53. data/src/com/redcareditor/plist/Dict.java +119 -0
  54. data/src/com/redcareditor/plist/PlistNode.java +52 -0
  55. data/src/com/redcareditor/plist/PlistPropertyLoader.java +44 -0
  56. data/src/com/redcareditor/theme/ScopeSelector.java +39 -0
  57. data/src/com/redcareditor/theme/Theme.java +122 -0
  58. data/src/com/redcareditor/theme/ThemeManager.java +41 -0
  59. data/src/com/redcareditor/theme/ThemeSetting.java +78 -0
  60. data/src/com/redcareditor/util/FileUtility.java +64 -0
  61. data/src/com/redcareditor/util/SingleLineFormatter.java +11 -0
  62. data/src/com/redcareditor/util/swt/ColourUtil.java +56 -0
  63. data/src/ruby/java-mateview.rb +68 -0
  64. data/test/com/redcareditor/mate/BundleTest.java +33 -0
  65. data/test/com/redcareditor/mate/EmptyRangeSetTest.java +27 -0
  66. data/test/com/redcareditor/mate/FilledRangeSetTest.java +82 -0
  67. data/test/com/redcareditor/mate/GrammarTest.java +158 -0
  68. data/test/com/redcareditor/mate/MateTextTest.java +35 -0
  69. data/test/com/redcareditor/mate/ScopeMatcherMatchingTest.java +55 -0
  70. data/test/com/redcareditor/mate/ScopeMatcherRankingTest.java +40 -0
  71. data/test/com/redcareditor/onig/RxTest.java +54 -0
  72. data/test/com/redcareditor/plist/DictTest.java +33 -0
  73. data/test/com/redcareditor/theme/RailsCastThemeTest.java +37 -0
  74. data/test/com/redcareditor/theme/ScopeSelectorTest.java +38 -0
  75. data/test/com/redcareditor/theme/ThemeManagerTest.java +29 -0
  76. data/test/com/redcareditor/util/swt/ColourUtilTest.java +17 -0
  77. metadata +142 -0
@@ -0,0 +1,15 @@
1
+ package com.redcareditor.mate.document;
2
+
3
+
4
+ public interface MateDocument extends MateTextFactory{
5
+
6
+ public int getLineCount();
7
+
8
+ public int getLineLength(int line);
9
+
10
+ public boolean addTextLocation(MateTextLocation location);
11
+
12
+ public boolean addTextLocation(String category, MateTextLocation location);
13
+
14
+ public void reparseAll();
15
+ }
@@ -0,0 +1,9 @@
1
+ package com.redcareditor.mate.document;
2
+
3
+ public interface MateTextFactory {
4
+ public MateTextLocation getTextLocation(int line, int offset);
5
+
6
+ public MateTextRange getTextRange();
7
+
8
+ public MateTextRange getTextRange(MateTextLocation start, MateTextLocation end);
9
+ }
@@ -0,0 +1,8 @@
1
+ package com.redcareditor.mate.document;
2
+
3
+ public interface MateTextLocation extends Comparable<MateTextLocation> {
4
+ public int getOffset();
5
+ public int getLine();
6
+ public int getLineOffset();
7
+ public void setDocument(MateDocument document);
8
+ }
@@ -0,0 +1,17 @@
1
+ package com.redcareditor.mate.document;
2
+
3
+ import java.util.Comparator;
4
+
5
+ public class MateTextLocationComparator implements Comparator<MateTextLocation> {
6
+
7
+ public int compare(MateTextLocation arg0, MateTextLocation arg1) {
8
+ int lineCompare = arg0.getLine() - arg1.getLine();
9
+
10
+ if (lineCompare == 0) {
11
+ return arg0.getLineOffset() - arg1.getLineOffset();
12
+ }
13
+
14
+ return lineCompare;
15
+ }
16
+
17
+ }
@@ -0,0 +1,18 @@
1
+ package com.redcareditor.mate.document;
2
+
3
+ public interface MateTextRange {
4
+
5
+ public MateTextLocation getStart();
6
+
7
+ public void setDocument(MateDocument document);
8
+ public void setStart(MateTextLocation location);
9
+
10
+ public MateTextLocation getEnd();
11
+
12
+ public void setEnd(MateTextLocation location);
13
+ public void clearEnd();
14
+
15
+ public int getLength();
16
+ public boolean conatains(MateTextLocation location);
17
+ public boolean overlaps(MateTextRange range);
18
+ }
@@ -0,0 +1,143 @@
1
+ package com.redcareditor.mate.document.swt;
2
+
3
+ import org.eclipse.jface.text.BadLocationException;
4
+ import org.eclipse.jface.text.BadPositionCategoryException;
5
+ import org.eclipse.jface.text.DefaultPositionUpdater;
6
+ import org.eclipse.jface.text.Document;
7
+ import org.eclipse.jface.text.IDocument;
8
+ import org.eclipse.jface.text.DocumentEvent;
9
+ import org.eclipse.jface.text.IDocumentListener;
10
+ import org.eclipse.jface.text.IPositionUpdater;
11
+ import org.eclipse.jface.text.Position;
12
+ import org.eclipse.swt.custom.StyledText;
13
+
14
+ import com.redcareditor.mate.MateText;
15
+ import com.redcareditor.mate.document.MateDocument;
16
+ import com.redcareditor.mate.document.MateTextFactory;
17
+ import com.redcareditor.mate.document.MateTextLocation;
18
+ import com.redcareditor.mate.document.MateTextRange;
19
+
20
+ public class SwtMateDocument implements MateDocument, MateTextFactory {
21
+ public MateText mateText;
22
+ private IPositionUpdater positionUpdater;
23
+ public Document document;
24
+
25
+ public SwtMateDocument(MateText mateText) {
26
+ this.mateText = mateText;
27
+ this.document = (Document) mateText.getDocument();
28
+ for (IPositionUpdater u : document.getPositionUpdaters()) {
29
+ document.removePositionUpdater(u);
30
+ }
31
+ document.addPositionCategory("scopes");
32
+ document.addPositionUpdater(new SwtScopePositionUpdater("scopes", SwtScopePositionUpdater.LEFT_GRAVITY));
33
+ document.addPositionCategory("lefts");
34
+ document.addPositionUpdater(new SwtScopePositionUpdater("lefts", SwtScopePositionUpdater.LEFT_GRAVITY));
35
+ document.addPositionCategory("rights");
36
+ document.addPositionUpdater(new SwtScopePositionUpdater("rights", SwtScopePositionUpdater.RIGHT_GRAVITY));
37
+ }
38
+
39
+ public void set(String text) {
40
+ this.mateText.getDocument().set(text);
41
+ //reparseAll();
42
+ }
43
+
44
+ public IDocument getJFaceDocument() {
45
+ return this.mateText.getDocument();
46
+ }
47
+
48
+ public String get() {
49
+ return this.mateText.getDocument().get();
50
+ }
51
+
52
+ public int length() {
53
+ return this.mateText.getDocument().getLength();
54
+ }
55
+
56
+ public int getNumberOfLines() {
57
+ return this.mateText.getDocument().getNumberOfLines();
58
+ }
59
+
60
+ public void reparseAll() {
61
+ SwtMateTextLocation startLocation = new SwtMateTextLocation(0, this);
62
+ SwtMateTextLocation endLocation = new SwtMateTextLocation(0 + document.getLength(), this);
63
+ if (this.mateText.parser.parserScheduler.enabled) {
64
+ this.mateText.parser.parserScheduler.changes.add(startLocation.getLine(), endLocation.getLine());
65
+ this.mateText.parser.parserScheduler.processChanges();
66
+ }
67
+ }
68
+
69
+ public void replace(int start, int length, String text) {
70
+ try {
71
+ this.mateText.getDocument().replace(start, length, text);
72
+ SwtMateTextLocation startLocation = new SwtMateTextLocation(start, this);
73
+ SwtMateTextLocation endLocation = new SwtMateTextLocation(start + length, this);
74
+ this.mateText.parser.parserScheduler.changes.add(startLocation.getLine(), endLocation.getLine());
75
+ this.mateText.parser.parserScheduler.processChanges();
76
+ } catch (BadLocationException e) {
77
+ // TODO: SwtMateDocument should throw it's own Exception here
78
+ }
79
+ }
80
+
81
+ public boolean addTextLocation(MateTextLocation location) {
82
+ return addTextLocation("default", location);
83
+ }
84
+
85
+ public boolean addTextLocation(String category, MateTextLocation location) {
86
+ try {
87
+ mateText.getDocument().addPosition(category, (SwtMateTextLocation) location);
88
+ return true;
89
+ } catch (BadLocationException e) {
90
+ // TODO Auto-generated catch block
91
+ e.printStackTrace();
92
+ } catch (BadPositionCategoryException e) {
93
+ e.printStackTrace();
94
+ }
95
+
96
+ return false;
97
+ }
98
+
99
+ public boolean removeTextLocation(String category, MateTextLocation location) {
100
+ try {
101
+ mateText.getDocument().removePosition(category, (SwtMateTextLocation) location);
102
+ return true;
103
+ } catch (BadPositionCategoryException e) {
104
+ e.printStackTrace();
105
+ }
106
+ return false;
107
+ }
108
+
109
+ public int getLineCount() {
110
+ return document.getNumberOfLines();
111
+ }
112
+
113
+ public int getLineLength(int line) {
114
+ try {
115
+ int startOffset = document.getLineOffset(line);
116
+ int endOffset;
117
+
118
+ if (line + 1 < getLineCount()) {
119
+ endOffset = document.getLineOffset(line + 1);
120
+ } else {
121
+ endOffset = document.getLength();
122
+ }
123
+
124
+ return endOffset - startOffset;
125
+ } catch (BadLocationException e) {
126
+ System.out.printf("*** Warning BadLocationException");
127
+ e.printStackTrace();
128
+ return -1;
129
+ }
130
+ }
131
+
132
+ public MateTextLocation getTextLocation(int line, int offset) {
133
+ return new SwtMateTextLocation(line, offset, this);
134
+ }
135
+
136
+ public MateTextRange getTextRange(MateTextLocation start, MateTextLocation end) {
137
+ return new SwtMateTextRange(start, end, this);
138
+ }
139
+
140
+ public MateTextRange getTextRange() {
141
+ return new SwtMateTextRange(this);
142
+ }
143
+ }
@@ -0,0 +1,88 @@
1
+ package com.redcareditor.mate.document.swt;
2
+
3
+ import org.eclipse.jface.text.Position;
4
+ import org.eclipse.jface.text.Document;
5
+ import org.eclipse.swt.custom.StyledText;
6
+ import org.eclipse.jface.text.BadLocationException;
7
+
8
+ import com.redcareditor.mate.document.MateDocument;
9
+ import com.redcareditor.mate.document.MateTextLocation;
10
+ import com.redcareditor.mate.document.MateTextLocationComparator;
11
+
12
+ public class SwtMateTextLocation extends Position implements MateTextLocation {
13
+
14
+ private static final MateTextLocationComparator comperator = new MateTextLocationComparator();
15
+ private Document document;
16
+
17
+ public SwtMateTextLocation(int offset, SwtMateDocument document) {
18
+ super(offset);
19
+ this.document = (Document) document.getJFaceDocument();
20
+ }
21
+
22
+ public SwtMateTextLocation(int line, int lineOffset, SwtMateDocument document) {
23
+ super(computeOffset(line, lineOffset, (Document) document.getJFaceDocument()));
24
+ this.document = (Document) document.getJFaceDocument();
25
+ }
26
+
27
+ public SwtMateTextLocation(MateTextLocation location, SwtMateDocument document) {
28
+ super(computeOffset(location.getLine(), location.getLineOffset(), (Document) document.getJFaceDocument()));
29
+ this.document = (Document) document.getJFaceDocument();
30
+ }
31
+
32
+ public void setDocument(MateDocument document) {
33
+ this.document = (Document) ((SwtMateDocument) document).getJFaceDocument();
34
+ }
35
+
36
+ public int getLine() {
37
+ try {
38
+ return document.getLineOfOffset(getOffset());
39
+ } catch (BadLocationException e) {
40
+ System.out.printf("*** Warning BadLocationException");
41
+ e.printStackTrace();
42
+ return -1;
43
+ }
44
+ }
45
+
46
+ public int getLineOffset() {
47
+ try {
48
+ return getOffset() - document.getLineOffset(getLine());
49
+ } catch (BadLocationException e) {
50
+ System.out.printf("*** Warning BadLocationException");
51
+ e.printStackTrace();
52
+ return -1;
53
+ }
54
+ }
55
+
56
+ public int compareTo(MateTextLocation other) {
57
+ return this.offset - ((SwtMateTextLocation)other).offset;
58
+ }
59
+
60
+ //@Override
61
+ //public int getOffset() {
62
+ // return this.offset < document.getLength() ? this.offset : document.getLength();
63
+ //}
64
+
65
+ private static int computeOffset(int line, int offset, Document document){
66
+ try {
67
+ line = line < 0 ? 0 : line;
68
+
69
+ int result = document.getLineOffset(line) + offset;
70
+
71
+ result = result < 0 ? 0 : result;
72
+ result = result > document.getLength() ? document.getLength() : result;
73
+ return result;
74
+ } catch (BadLocationException e) {
75
+ System.out.printf("*** Warning BadLocationException");
76
+ e.printStackTrace();
77
+ return -1;
78
+ }
79
+ }
80
+
81
+ @Override
82
+ public boolean equals(Object other) {
83
+ if(other instanceof MateTextLocation){
84
+ return compareTo((MateTextLocation) other) == 0;
85
+ }
86
+ return false;
87
+ }
88
+ }
@@ -0,0 +1,92 @@
1
+ package com.redcareditor.mate.document.swt;
2
+
3
+ import org.eclipse.jface.text.Document;
4
+ import org.eclipse.jface.text.BadLocationException;
5
+
6
+ import com.redcareditor.mate.document.MateDocument;
7
+ import com.redcareditor.mate.document.MateTextLocation;
8
+ import com.redcareditor.mate.document.MateTextRange;
9
+
10
+ public class SwtMateTextRange implements MateTextRange {
11
+ private SwtMateTextLocation start;
12
+ private SwtMateTextLocation end;
13
+ private SwtMateDocument document;
14
+
15
+ public SwtMateTextRange(SwtMateDocument document) {
16
+ this.document = document;
17
+ }
18
+
19
+ public SwtMateTextRange(MateTextLocation start, MateTextLocation end, SwtMateDocument document) {
20
+ super();
21
+ this.start = sanatize(start);
22
+ this.end = sanatize(end);
23
+ this.document = document;
24
+ }
25
+
26
+ public void setDocument(MateDocument document) {
27
+ this.document = (SwtMateDocument) document;
28
+ if (start != null)
29
+ start.setDocument(document);
30
+ if (end != null)
31
+ end.setDocument(document);
32
+ }
33
+
34
+ public int getLength() {
35
+ return end.getOffset() - start.getOffset();
36
+ }
37
+
38
+ public MateTextLocation getStart() {
39
+ if (start != null) {
40
+ return start;
41
+ } else {
42
+ return document.getTextLocation(0, 0);
43
+ }
44
+ }
45
+
46
+ public void setStart(MateTextLocation location) {
47
+ start = sanatize(location);
48
+ }
49
+
50
+ public MateTextLocation getEnd() {
51
+ if (end != null) {
52
+ return end;
53
+ } else {// Return end of Document if not set
54
+ try {
55
+ int lastLine = document.document.getNumberOfLines() - 1;
56
+ int lastLineOffset = document.document.getLength() - document.document.getLineOffset(lastLine);
57
+ return document.getTextLocation(lastLine, lastLineOffset);
58
+ } catch (BadLocationException e) {
59
+ System.out.printf("*** Warning BadLocationException");
60
+ e.printStackTrace();
61
+ return null;
62
+ }
63
+ }
64
+ }
65
+
66
+ public void setEnd(MateTextLocation location) {
67
+ end = sanatize(location);
68
+ }
69
+
70
+ public void clearEnd() {
71
+ end = null;
72
+ }
73
+
74
+ private SwtMateTextLocation sanatize(MateTextLocation location) {
75
+ if (location instanceof SwtMateTextLocation) {
76
+ return (SwtMateTextLocation) location;
77
+ }
78
+ return (SwtMateTextLocation) document.getTextLocation(location.getLine(), location.getLineOffset());
79
+ }
80
+
81
+ public boolean conatains(MateTextLocation location) {
82
+ return getStart().compareTo(location) <= 0 && getEnd().compareTo(location) > 0;
83
+ }
84
+
85
+ public boolean overlaps(MateTextRange range) {
86
+ if(getStart().compareTo(range.getStart()) >= 0){
87
+ return getStart().compareTo(range.getEnd()) <= 0;
88
+ }else{
89
+ return getEnd().compareTo(range.getStart()) >= 0;
90
+ }
91
+ }
92
+ }
@@ -0,0 +1,90 @@
1
+ package com.redcareditor.mate.document.swt;
2
+
3
+ import org.eclipse.jface.text.BadPositionCategoryException;
4
+ import org.eclipse.jface.text.DocumentEvent;
5
+ import org.eclipse.jface.text.IPositionUpdater;
6
+ import org.eclipse.jface.text.Position;
7
+
8
+ /**
9
+ * ScopePositionUpdater
10
+ *
11
+ * A position updater that never deletes a position. If the region containing
12
+ * the position is deleted, the position is moved to the beginning/end (falling
13
+ * together) of the change. If the region containing the position is replaced,
14
+ * the position is placed at the same location inside the replacement text, but
15
+ * always inside the replacement text.
16
+ *
17
+ * @since 3.1
18
+ */
19
+ public class SwtScopePositionUpdater implements IPositionUpdater {
20
+ static final int LEFT_GRAVITY = 0;
21
+ static final int RIGHT_GRAVITY = 1;
22
+
23
+ /** The position category. */
24
+ private final String fCategory;
25
+ private final int fGravity;
26
+
27
+ /**
28
+ * Creates a new updater for the given <code>category</code>.
29
+ *
30
+ * @param category the new category.
31
+ */
32
+ public SwtScopePositionUpdater(String category, int gravity) {
33
+ fCategory = category;
34
+ fGravity = gravity;
35
+ }
36
+
37
+ /*
38
+ * @see org.eclipse.jface.text.IPositionUpdater#update(org.eclipse.jface.text.DocumentEvent)
39
+ */
40
+ public void update(DocumentEvent event) {
41
+ int eventOffset = event.getOffset();
42
+ int eventOldEndOffset = eventOffset + event.getLength();
43
+ int eventNewLength = event.getText() == null ? 0 : event.getText().length();
44
+ int eventNewEndOffset = eventOffset + eventNewLength;
45
+ int deltaLength = eventNewLength - event.getLength();
46
+ //System.out.printf("SwtScopePositionUpdater cat:%s grav:%d delta:%d\n", fCategory, fGravity, deltaLength);
47
+
48
+ try {
49
+ Position[] positions= event.getDocument().getPositions(fCategory);
50
+ for (int i= 0; i != positions.length; i++) {
51
+
52
+ Position position= positions[i];
53
+
54
+ if (position.isDeleted())
55
+ continue;
56
+
57
+ int posOffset = position.getOffset();
58
+ int posLength = position.getLength(); // always zero
59
+ int posEnd = posOffset + posLength;
60
+ //System.out.printf(" position %s offset:%d\n", position.toString(), posOffset);
61
+
62
+ if (posOffset > eventOldEndOffset) {
63
+ // position comes way after change - shift
64
+ position.setOffset(posOffset + deltaLength);
65
+ } else if (posOffset < eventOffset) {
66
+ // position comes way before change - leave alone
67
+ } else {
68
+ // position is within replaced text -
69
+ if (fGravity == RIGHT_GRAVITY)
70
+ position.setOffset(eventNewEndOffset);
71
+ else
72
+ position.setOffset(eventOffset);
73
+ }
74
+ //System.out.printf(" position %s offset:%d\n", position.toString(), position.getOffset());
75
+ }
76
+ } catch (BadPositionCategoryException e) {
77
+ // ignore and return
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Returns the position category.
83
+ *
84
+ * @return the position category
85
+ */
86
+ public String getCategory() {
87
+ return fCategory;
88
+ }
89
+
90
+ }