blob: fc2c13df40d40ac7b0652e786d278bd90eeea7db (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
/*******************************************************************************
* Copyright (c) 2006, 2015 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ui.internal.texteditor.rulers;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.content.IContentType;
/**
* Describes the target of a contribution to the <code>org.eclipse.ui.texteditor.rulerColumns</code>
* extension point.
*
* @since 3.3
*/
public abstract class RulerColumnTarget {
public abstract boolean matchesEditorId(String editorId);
public abstract boolean matchesContentType(IContentType contentType);
public abstract boolean matchesClass(Class<?> clazz);
/* package visible */
RulerColumnTarget() {
}
public static RulerColumnTarget createAllTarget() {
return new AllTarget();
}
public static RulerColumnTarget createOrTarget(RulerColumnTarget either, RulerColumnTarget or) {
Assert.isLegal(or != null || either != null);
if (either == null)
return or;
if (or == null)
return either;
return new OrTarget(either, or);
}
public static RulerColumnTarget createContentTypeTarget(String contentTypeId) {
return new ContentTypeTarget(contentTypeId);
}
public static RulerColumnTarget createEditorIdTarget(String editorId) {
return new EditorIdTarget(editorId);
}
public static RulerColumnTarget createClassTarget(String className) {
return new ClassTarget(className);
}
}
final class AllTarget extends RulerColumnTarget {
AllTarget() {
}
@Override
public boolean matchesContentType(IContentType contentType) {
return true;
}
@Override
public boolean matchesEditorId(String editorId) {
return true;
}
@Override
public boolean matchesClass(Class<?> clazz) {
return true;
}
@Override
public String toString() {
return "All"; //$NON-NLS-1$
}
}
final class OrTarget extends RulerColumnTarget {
private final RulerColumnTarget fEither;
private final RulerColumnTarget fOr;
OrTarget(RulerColumnTarget either, RulerColumnTarget or) {
fEither= either;
fOr= or;
Assert.isLegal(either != null);
Assert.isLegal(or != null);
}
@Override
public boolean matchesContentType(IContentType contentType) {
return fEither.matchesContentType(contentType) || fOr.matchesContentType(contentType);
}
@Override
public boolean matchesEditorId(String editorId) {
return fEither.matchesEditorId(editorId) || fOr.matchesEditorId(editorId);
}
@Override
public boolean matchesClass(Class<?> clazz) {
return fEither.matchesClass(clazz) || fOr.matchesClass(clazz);
}
@Override
public String toString() {
return fEither.toString() + " || " + fOr.toString(); //$NON-NLS-1$
}
}
final class EditorIdTarget extends RulerColumnTarget {
private final String fEditorId;
EditorIdTarget(String id) {
Assert.isLegal(id != null);
fEditorId= id;
}
@Override
public boolean matchesContentType(IContentType contentType) {
return false;
}
@Override
public boolean matchesEditorId(String editorId) {
return fEditorId.equals(editorId);
}
@Override
public boolean matchesClass(Class<?> clazz) {
return false;
}
@Override
public String toString() {
return "editorID=" + fEditorId; //$NON-NLS-1$
}
}
final class ClassTarget extends RulerColumnTarget {
private final String fClassName;
ClassTarget(String className) {
Assert.isLegal(className != null);
fClassName= className;
}
@Override
public boolean matchesContentType(IContentType contentType) {
return false;
}
@Override
public boolean matchesEditorId(String editorId) {
return false;
}
@Override
public boolean matchesClass(Class<?> clazz) {
Assert.isLegal(clazz != null);
do {
if (clazz.getName().equals(fClassName))
return true;
clazz= clazz.getSuperclass();
} while (clazz != null);
return false;
}
@Override
public String toString() {
return "class=" + fClassName; //$NON-NLS-1$
}
}
final class ContentTypeTarget extends RulerColumnTarget {
private final IContentType fContentType;
ContentTypeTarget(String contentTypeId) {
Assert.isLegal(contentTypeId != null);
fContentType= Platform.getContentTypeManager().getContentType(contentTypeId);
}
@Override
public boolean matchesContentType(IContentType contentType) {
return fContentType != null && contentType != null && contentType.isKindOf(fContentType);
}
@Override
public boolean matchesEditorId(String editorId) {
return false;
}
@Override
public boolean matchesClass(Class<?> clazz) {
return false;
}
@Override
public String toString() {
return "contentType=" + fContentType; //$NON-NLS-1$
}
}
|