View | Details | Raw Unified | Return to bug 185488 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/dltk/tcl/core/TclPlugin.java (+2 lines)
Lines 10-15 Link Here
10
package org.eclipse.dltk.tcl.core;
10
package org.eclipse.dltk.tcl.core;
11
11
12
import org.eclipse.core.runtime.Plugin;
12
import org.eclipse.core.runtime.Plugin;
13
import org.eclipse.dltk.compiler.task.TodoTaskPreferences;
13
import org.osgi.framework.BundleContext;
14
import org.osgi.framework.BundleContext;
14
15
15
/**
16
/**
Lines 34-39 Link Here
34
	 */
35
	 */
35
	public void start(BundleContext context) throws Exception {
36
	public void start(BundleContext context) throws Exception {
36
		super.start(context);		
37
		super.start(context);		
38
		new TodoTaskPreferences(getPluginPreferences()).initializeDefaultValues();
37
	}
39
	}
38
40
39
	/**
41
	/**
(-)src/org/eclipse/dltk/tcl/internal/parser/TclSourceElementParser.java (-25 / +36 lines)
Lines 2-14 Link Here
2
2
3
import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
3
import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
4
import org.eclipse.dltk.compiler.SourceElementRequestVisitor;
4
import org.eclipse.dltk.compiler.SourceElementRequestVisitor;
5
import org.eclipse.dltk.compiler.task.ITaskReporter;
6
import org.eclipse.dltk.compiler.task.TodoTaskPreferences;
7
import org.eclipse.dltk.compiler.task.TodoTaskSimpleParser;
5
import org.eclipse.dltk.core.AbstractSourceElementParser;
8
import org.eclipse.dltk.core.AbstractSourceElementParser;
6
import org.eclipse.dltk.core.DLTKCore;
7
import org.eclipse.dltk.core.IScriptProject;
9
import org.eclipse.dltk.core.IScriptProject;
8
import org.eclipse.dltk.core.ISourceElementParserExtension;
10
import org.eclipse.dltk.core.ISourceElementParserExtension;
9
import org.eclipse.dltk.core.SourceParserUtil;
11
import org.eclipse.dltk.core.ISourceModule;
10
import org.eclipse.dltk.core.ISourceModuleInfoCache.ISourceModuleInfo;
12
import org.eclipse.dltk.core.ISourceModuleInfoCache.ISourceModuleInfo;
11
import org.eclipse.dltk.tcl.core.TclNature;
13
import org.eclipse.dltk.tcl.core.TclNature;
14
import org.eclipse.dltk.tcl.core.TclPlugin;
12
import org.eclipse.dltk.tcl.core.TclParseUtil.CodeModel;
15
import org.eclipse.dltk.tcl.core.TclParseUtil.CodeModel;
13
16
14
public class TclSourceElementParser extends AbstractSourceElementParser
17
public class TclSourceElementParser extends AbstractSourceElementParser
Lines 20-55 Link Here
20
	 * @see org.eclipse.dltk.core.AbstractSourceElementParser#createVisitor()
23
	 * @see org.eclipse.dltk.core.AbstractSourceElementParser#createVisitor()
21
	 */
24
	 */
22
	protected SourceElementRequestVisitor createVisitor() {
25
	protected SourceElementRequestVisitor createVisitor() {
23
		return new TclSourceElementRequestVisitor(this.getRequestor(), this
26
		return new TclSourceElementRequestVisitor(getRequestor(),
24
				.getProblemReporter());
27
				getProblemReporter());
25
	}
28
	}
26
29
27
	public void parseSourceModule(char[] contents, ISourceModuleInfo astCache,
30
	public void parseSourceModule(char[] contents, ISourceModuleInfo astCache,
28
			char[] filename) {
31
			char[] filename) {
32
		final ModuleDeclaration declaration = parseSource(filename, contents);
33
		TclSourceElementRequestVisitor requestor = (TclSourceElementRequestVisitor) createVisitor();
34
		if (getProblemReporter() != null && scriptProject != null) {
35
			requestor.setCodeModel(new CodeModel(new String(contents)));
36
			requestor.setScriptProject(this.scriptProject);
37
		}
38
		traverse(declaration, requestor);
39
		parseTasks(contents);
40
	}
29
41
30
		ModuleDeclaration moduleDeclaration = SourceParserUtil
42
	public void processModule(ISourceModule module,
31
				.getModuleDeclaration(filename, contents, getNatureId(),
43
			ModuleDeclaration declaration, char[] content) {
32
						getProblemReporter(), astCache);
33
		//
34
35
		TclSourceElementRequestVisitor requestor = (TclSourceElementRequestVisitor) createVisitor();
44
		TclSourceElementRequestVisitor requestor = (TclSourceElementRequestVisitor) createVisitor();
36
		requestor.setScriptProject(null);
45
		if (content != null && getProblemReporter() != null
37
		if (getProblemReporter() != null) {
46
				&& scriptProject != null) {
38
			if (this.scriptProject != null) {
47
			requestor.setCodeModel(new CodeModel(new String(content)));
39
				boolean markersCleaned = getProblemReporter()
48
			requestor.setScriptProject(this.scriptProject);
40
						.isMarkersCleaned();
49
		}
41
				if (markersCleaned) {
50
		traverse(declaration, requestor);
42
					CodeModel model = new CodeModel(new String(contents));
51
		if (content != null) {
43
					requestor.setCodeModel(model);
52
			parseTasks(content);
44
					requestor.setScriptProject(this.scriptProject);
45
				}
46
			}
47
		}
53
		}
48
		try {
54
	}
49
			moduleDeclaration.traverse(requestor);
55
50
		} catch (Exception e) {
56
	protected void parseTasks(ITaskReporter taskReporter, char[] content) {
51
			if (DLTKCore.DEBUG) {
57
		final TodoTaskPreferences preferences = new TodoTaskPreferences(
52
				e.printStackTrace();
58
				TclPlugin.getDefault().getPluginPreferences());
59
		if (preferences.isEnabled()) {
60
			final TodoTaskSimpleParser taskParser = new TodoTaskSimpleParser(
61
					taskReporter, preferences);
62
			if (taskParser.isValid()) {
63
				taskParser.parse(content);
53
			}
64
			}
54
		}
65
		}
55
	}
66
	}
(-)src/org/eclipse/dltk/ui/preferences/AbstractConfigurationBlock.java (+5 lines)
Lines 49-54 Link Here
49
import org.eclipse.swt.widgets.Control;
49
import org.eclipse.swt.widgets.Control;
50
import org.eclipse.swt.widgets.Group;
50
import org.eclipse.swt.widgets.Group;
51
import org.eclipse.swt.widgets.Label;
51
import org.eclipse.swt.widgets.Label;
52
import org.eclipse.swt.widgets.Shell;
52
import org.eclipse.swt.widgets.Text;
53
import org.eclipse.swt.widgets.Text;
53
import org.eclipse.ui.forms.events.ExpansionAdapter;
54
import org.eclipse.ui.forms.events.ExpansionAdapter;
54
import org.eclipse.ui.forms.events.ExpansionEvent;
55
import org.eclipse.ui.forms.events.ExpansionEvent;
Lines 327-332 Link Here
327
	private org.eclipse.dltk.internal.ui.dialogs.StatusInfo fStatus;
328
	private org.eclipse.dltk.internal.ui.dialogs.StatusInfo fStatus;
328
329
329
	private final PreferencePage fMainPage;
330
	private final PreferencePage fMainPage;
331
	
332
	protected Shell getShell() {
333
		return fMainPage.getShell();
334
	}
330
335
331
	public AbstractConfigurationBlock(OverlayPreferenceStore store) {
336
	public AbstractConfigurationBlock(OverlayPreferenceStore store) {
332
		Assert.isNotNull(store);
337
		Assert.isNotNull(store);
(-)src/org/eclipse/dltk/ui/preferences/PreferencesMessages.java (-20 / +20 lines)
Lines 229-259 Link Here
229
//	public static String CodeFormatterPreferencePage_description;
229
//	public static String CodeFormatterPreferencePage_description;
230
//	public static String TodoTaskPreferencePage_title;
230
//	public static String TodoTaskPreferencePage_title;
231
//	public static String TodoTaskPreferencePage_description;
231
//	public static String TodoTaskPreferencePage_description;
232
//	public static String TodoTaskConfigurationBlock_markers_tasks_high_priority;
232
	public static String TodoTaskConfigurationBlock_markers_tasks_high_priority;
233
//	public static String TodoTaskConfigurationBlock_markers_tasks_normal_priority;
233
	public static String TodoTaskConfigurationBlock_markers_tasks_normal_priority;
234
//	public static String TodoTaskConfigurationBlock_markers_tasks_low_priority;
234
	public static String TodoTaskConfigurationBlock_markers_tasks_low_priority;
235
//	public static String TodoTaskConfigurationBlock_markers_tasks_add_button;
235
	public static String TodoTaskConfigurationBlock_markers_tasks_add_button;
236
//	public static String TodoTaskConfigurationBlock_markers_tasks_remove_button;
236
	public static String TodoTaskConfigurationBlock_markers_tasks_remove_button;
237
//	public static String TodoTaskConfigurationBlock_markers_tasks_edit_button;
237
	public static String TodoTaskConfigurationBlock_markers_tasks_edit_button;
238
//	public static String TodoTaskConfigurationBlock_markers_tasks_name_column;
238
	public static String TodoTaskConfigurationBlock_markers_tasks_name_column;
239
//	public static String TodoTaskConfigurationBlock_markers_tasks_priority_column;
239
	public static String TodoTaskConfigurationBlock_markers_tasks_priority_column;
240
//	public static String TodoTaskConfigurationBlock_markers_tasks_setdefault_button;
240
//	public static String TodoTaskConfigurationBlock_markers_tasks_setdefault_button;
241
//	public static String TodoTaskConfigurationBlock_casesensitive_label;
241
	public static String TodoTaskConfigurationBlock_casesensitive_label;
242
//	public static String TodoTaskConfigurationBlock_needsbuild_title;
242
//	public static String TodoTaskConfigurationBlock_needsbuild_title;
243
//	public static String TodoTaskConfigurationBlock_tasks_default;
243
//	public static String TodoTaskConfigurationBlock_tasks_default;
244
//	public static String TodoTaskConfigurationBlock_needsfullbuild_message;
244
//	public static String TodoTaskConfigurationBlock_needsfullbuild_message;
245
//	public static String TodoTaskConfigurationBlock_needsprojectbuild_message;
245
//	public static String TodoTaskConfigurationBlock_needsprojectbuild_message;
246
//	public static String TodoTaskInputDialog_new_title;
246
	public static String TodoTaskInputDialog_new_title;
247
//	public static String TodoTaskInputDialog_edit_title;
247
	public static String TodoTaskInputDialog_edit_title;
248
//	public static String TodoTaskInputDialog_name_label;
248
	public static String TodoTaskInputDialog_name_label;
249
//	public static String TodoTaskInputDialog_priority_label;
249
	public static String TodoTaskInputDialog_priority_label;
250
//	public static String TodoTaskInputDialog_priority_high;
250
	public static String TodoTaskInputDialog_priority_high;
251
//	public static String TodoTaskInputDialog_priority_normal;
251
	public static String TodoTaskInputDialog_priority_normal;
252
//	public static String TodoTaskInputDialog_priority_low;
252
	public static String TodoTaskInputDialog_priority_low;
253
//	public static String TodoTaskInputDialog_error_enterName;
253
	public static String TodoTaskInputDialog_error_enterName;
254
//	public static String TodoTaskInputDialog_error_comma;
254
	public static String TodoTaskInputDialog_error_comma;
255
//	public static String TodoTaskInputDialog_error_entryExists;
255
	public static String TodoTaskInputDialog_error_entryExists;
256
//	public static String TodoTaskInputDialog_error_noSpace;
256
	public static String TodoTaskInputDialog_error_noSpace;
257
257
258
	public static String PropertyAndPreferencePage_useworkspacesettings_change;
258
	public static String PropertyAndPreferencePage_useworkspacesettings_change;
259
	public static String PropertyAndPreferencePage_showprojectspecificsettings_label;
259
	public static String PropertyAndPreferencePage_showprojectspecificsettings_label;
(-)src/org/eclipse/dltk/ui/preferences/PreferencesMessages.properties (+26 lines)
Lines 274-276 Link Here
274
AbstractConfigurationBlock_fileDoesntExist=File doesn't exist
274
AbstractConfigurationBlock_fileDoesntExist=File doesn't exist
275
AbstractConfigurationBlock_pathIsntAFile=Path isn't a file
275
AbstractConfigurationBlock_pathIsntAFile=Path isn't a file
276
AbstractConfigurationBlock_valuesItemsAndLabelMustNotBeNull=values == null || items == null || label == null
276
AbstractConfigurationBlock_valuesItemsAndLabelMustNotBeNull=values == null || items == null || label == null
277
278
TodoTaskConfigurationBlock_markers_tasks_high_priority=High
279
TodoTaskConfigurationBlock_markers_tasks_normal_priority=Normal
280
TodoTaskConfigurationBlock_markers_tasks_low_priority=Low
281
282
TodoTaskConfigurationBlock_markers_tasks_add_button=&New...
283
TodoTaskConfigurationBlock_markers_tasks_remove_button=&Remove
284
TodoTaskConfigurationBlock_markers_tasks_edit_button=&Edit...
285
#TodoTaskConfigurationBlock_markers_tasks_setdefault_button=Defa&ult
286
287
TodoTaskConfigurationBlock_markers_tasks_name_column=Tag
288
TodoTaskConfigurationBlock_markers_tasks_priority_column=Priority
289
290
TodoTaskConfigurationBlock_casesensitive_label=&Case sensitive task tag names
291
292
TodoTaskInputDialog_new_title=New Task Tag
293
TodoTaskInputDialog_edit_title=Edit Task Tag
294
TodoTaskInputDialog_name_label=T&ag:
295
TodoTaskInputDialog_priority_label=&Priority:
296
TodoTaskInputDialog_priority_high=High
297
TodoTaskInputDialog_priority_normal=Normal
298
TodoTaskInputDialog_priority_low=Low
299
TodoTaskInputDialog_error_enterName=Enter task tag name.
300
TodoTaskInputDialog_error_comma=Name cannot contain a comma or semicolon.
301
TodoTaskInputDialog_error_entryExists=An entry with the same name already exists.
302
TodoTaskInputDialog_error_noSpace=Name cannot begin or end with a whitespace.
(-)src/org/eclipse/dltk/ui/preferences/TodoTaskAbstractPreferencePage.java (+32 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 xored software, Inc.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *     xored software, Inc. - initial API and Implementation (Alex Panchenko)
11
 *******************************************************************************/
12
package org.eclipse.dltk.ui.preferences;
13
14
import org.eclipse.core.runtime.Preferences;
15
import org.eclipse.dltk.ui.PreferencesAdapter;
16
17
public abstract class TodoTaskAbstractPreferencePage extends
18
		AbstractConfigurationBlockPreferencePage {
19
20
	protected abstract Preferences getPluginPreferences();
21
22
	protected IPreferenceConfigurationBlock createConfigurationBlock(
23
			OverlayPreferenceStore overlayPreferenceStore) {
24
		return new TodoTaskConfigurationBlock(getPluginPreferences(),
25
				overlayPreferenceStore, this);
26
	}
27
28
	protected void setPreferenceStore() {
29
		setPreferenceStore(new PreferencesAdapter(getPluginPreferences()));
30
	}
31
32
}
(-)src/org/eclipse/dltk/ui/preferences/TodoTaskInputDialog.java (+165 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.dltk.ui.preferences;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
16
import org.eclipse.dltk.compiler.task.TodoTask;
17
import org.eclipse.dltk.compiler.task.TodoTaskPreferences;
18
import org.eclipse.dltk.internal.ui.dialogs.StatusInfo;
19
import org.eclipse.dltk.internal.ui.wizards.dialogfields.ComboDialogField;
20
import org.eclipse.dltk.internal.ui.wizards.dialogfields.DialogField;
21
import org.eclipse.dltk.internal.ui.wizards.dialogfields.IDialogFieldListener;
22
import org.eclipse.dltk.internal.ui.wizards.dialogfields.LayoutUtil;
23
import org.eclipse.dltk.internal.ui.wizards.dialogfields.StringDialogField;
24
import org.eclipse.jface.dialogs.StatusDialog;
25
import org.eclipse.swt.SWT;
26
import org.eclipse.swt.layout.GridLayout;
27
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Control;
29
import org.eclipse.swt.widgets.Shell;
30
31
/**
32
 * Dialog to enter a new task tag
33
 */
34
public class TodoTaskInputDialog extends StatusDialog {
35
36
	private class CompilerTodoTaskInputAdapter implements IDialogFieldListener {
37
		public void dialogFieldChanged(DialogField field) {
38
			doValidation();
39
		}
40
	}
41
42
	private StringDialogField fNameDialogField;
43
	private ComboDialogField fPriorityDialogField;
44
45
	private List fExistingNames;
46
47
	public TodoTaskInputDialog(Shell parent, TodoTask task, List existingEntries) {
48
		super(parent);
49
50
		fExistingNames = new ArrayList(existingEntries.size());
51
		for (int i = 0; i < existingEntries.size(); i++) {
52
			TodoTask curr = (TodoTask) existingEntries.get(i);
53
			if (!curr.equals(task)) {
54
				fExistingNames.add(curr.name);
55
			}
56
		}
57
58
		if (task == null) {
59
			setTitle(PreferencesMessages.TodoTaskInputDialog_new_title);
60
		} else {
61
			setTitle(PreferencesMessages.TodoTaskInputDialog_edit_title);
62
		}
63
64
		CompilerTodoTaskInputAdapter adapter = new CompilerTodoTaskInputAdapter();
65
66
		fNameDialogField = new StringDialogField();
67
		fNameDialogField
68
				.setLabelText(PreferencesMessages.TodoTaskInputDialog_name_label);
69
		fNameDialogField.setDialogFieldListener(adapter);
70
71
		fNameDialogField.setText((task != null) ? task.name : ""); //$NON-NLS-1$
72
73
		String[] items = new String[] {
74
				PreferencesMessages.TodoTaskInputDialog_priority_high,
75
				PreferencesMessages.TodoTaskInputDialog_priority_normal,
76
				PreferencesMessages.TodoTaskInputDialog_priority_low };
77
78
		fPriorityDialogField = new ComboDialogField(SWT.READ_ONLY);
79
		fPriorityDialogField
80
				.setLabelText(PreferencesMessages.TodoTaskInputDialog_priority_label);
81
		fPriorityDialogField.setItems(items);
82
		if (task != null) {
83
			if (TodoTask.PRIORITY_HIGH.equals(task.priority)) {
84
				fPriorityDialogField.selectItem(0);
85
			} else if (TodoTask.PRIORITY_NORMAL.equals(task.priority)) {
86
				fPriorityDialogField.selectItem(1);
87
			} else {
88
				fPriorityDialogField.selectItem(2);
89
			}
90
		} else {
91
			fPriorityDialogField.selectItem(1);
92
		}
93
	}
94
95
	public TodoTask getResult() {
96
		TodoTask task = new TodoTask();
97
		task.name = fNameDialogField.getText().trim();
98
		switch (fPriorityDialogField.getSelectionIndex()) {
99
		case 0:
100
			task.priority = TodoTask.PRIORITY_HIGH;
101
			break;
102
		case 1:
103
			task.priority = TodoTask.PRIORITY_NORMAL;
104
			break;
105
		default:
106
			task.priority = TodoTask.PRIORITY_LOW;
107
			break;
108
		}
109
		return task;
110
	}
111
112
	protected Control createDialogArea(Composite parent) {
113
		Composite composite = (Composite) super.createDialogArea(parent);
114
115
		Composite inner = new Composite(composite, SWT.NONE);
116
		GridLayout layout = new GridLayout();
117
		layout.marginHeight = 0;
118
		layout.marginWidth = 0;
119
		layout.numColumns = 2;
120
		inner.setLayout(layout);
121
122
		fNameDialogField.doFillIntoGrid(inner, 2);
123
		fPriorityDialogField.doFillIntoGrid(inner, 2);
124
125
		LayoutUtil.setHorizontalGrabbing(fNameDialogField.getTextControl(null));
126
		LayoutUtil.setWidthHint(fNameDialogField.getTextControl(null),
127
				convertWidthInCharsToPixels(45));
128
129
		fNameDialogField.postSetFocusOnDialogField(parent.getDisplay());
130
131
		applyDialogFont(composite);
132
133
		return composite;
134
	}
135
136
	private void doValidation() {
137
		StatusInfo status = new StatusInfo();
138
		String newText = fNameDialogField.getText();
139
		if (newText.length() == 0) {
140
			status
141
					.setError(PreferencesMessages.TodoTaskInputDialog_error_enterName);
142
		} else {
143
			if (!TodoTaskPreferences.isValidName(newText)) {
144
				status
145
						.setError(PreferencesMessages.TodoTaskInputDialog_error_comma);
146
			} else if (fExistingNames.contains(newText)) {
147
				status
148
						.setError(PreferencesMessages.TodoTaskInputDialog_error_entryExists);
149
			} else if (Character.isWhitespace(newText.charAt(0))
150
					|| Character.isWhitespace(newText
151
							.charAt(newText.length() - 1))) {
152
				status
153
						.setError(PreferencesMessages.TodoTaskInputDialog_error_noSpace);
154
			}
155
		}
156
		updateStatus(status);
157
	}
158
159
	/*
160
	 * @see org.eclipse.jface.window.Window#configureShell(Shell)
161
	 */
162
	protected void configureShell(Shell newShell) {
163
		super.configureShell(newShell);
164
	}
165
}
(-)src/org/eclipse/dltk/ui/preferences/TodoTaskConfigurationBlock.java (+254 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.dltk.ui.preferences;
12
13
import java.util.List;
14
15
import org.eclipse.core.runtime.Preferences;
16
import org.eclipse.dltk.compiler.task.TodoTask;
17
import org.eclipse.dltk.compiler.task.TodoTaskPreferences;
18
import org.eclipse.dltk.internal.ui.wizards.dialogfields.DialogField;
19
import org.eclipse.dltk.internal.ui.wizards.dialogfields.IDialogFieldListener;
20
import org.eclipse.dltk.internal.ui.wizards.dialogfields.IListAdapter;
21
import org.eclipse.dltk.internal.ui.wizards.dialogfields.ListDialogField;
22
import org.eclipse.dltk.ui.preferences.OverlayPreferenceStore.OverlayKey;
23
import org.eclipse.dltk.ui.util.PixelConverter;
24
import org.eclipse.jface.preference.PreferencePage;
25
import org.eclipse.jface.viewers.ITableLabelProvider;
26
import org.eclipse.jface.viewers.LabelProvider;
27
import org.eclipse.jface.viewers.Viewer;
28
import org.eclipse.jface.viewers.ViewerSorter;
29
import org.eclipse.jface.window.Window;
30
import org.eclipse.swt.SWT;
31
import org.eclipse.swt.events.SelectionAdapter;
32
import org.eclipse.swt.events.SelectionEvent;
33
import org.eclipse.swt.graphics.Image;
34
import org.eclipse.swt.layout.GridData;
35
import org.eclipse.swt.layout.GridLayout;
36
import org.eclipse.swt.widgets.Button;
37
import org.eclipse.swt.widgets.Composite;
38
import org.eclipse.swt.widgets.Control;
39
40
public class TodoTaskConfigurationBlock extends AbstractConfigurationBlock {
41
42
	private class TodoTaskLabelProvider extends LabelProvider implements
43
			ITableLabelProvider {
44
45
		/*
46
		 * (non-Javadoc)
47
		 * 
48
		 * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
49
		 */
50
		public Image getImage(Object element) {
51
			return null;
52
		}
53
54
		/*
55
		 * (non-Javadoc)
56
		 * 
57
		 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
58
		 */
59
		public String getText(Object element) {
60
			return getColumnText(element, 0);
61
		}
62
63
		/*
64
		 * (non-Javadoc)
65
		 * 
66
		 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object,
67
		 *      int)
68
		 */
69
		public Image getColumnImage(Object element, int columnIndex) {
70
			return null;
71
		}
72
73
		/*
74
		 * (non-Javadoc)
75
		 * 
76
		 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object,
77
		 *      int)
78
		 */
79
		public String getColumnText(Object element, int columnIndex) {
80
			final TodoTask task = (TodoTask) element;
81
			if (columnIndex == 0) {
82
				return task.name;
83
			} else {
84
				if (TodoTask.PRIORITY_HIGH.equals(task.priority)) {
85
					return PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_high_priority;
86
				} else if (TodoTask.PRIORITY_NORMAL.equals(task.priority)) {
87
					return PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_normal_priority;
88
				} else if (TodoTask.PRIORITY_LOW.equals(task.priority)) {
89
					return PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_low_priority;
90
				}
91
				return ""; //$NON-NLS-1$
92
			}
93
		}
94
95
	}
96
97
	private static class TodoTaskSorter extends ViewerSorter {
98
		public int compare(Viewer viewer, Object e1, Object e2) {
99
			return getComparator().compare(((TodoTask) e1).name,
100
					((TodoTask) e2).name);
101
		}
102
	}
103
104
	private static final int IDX_ADD = 0;
105
	private static final int IDX_EDIT = 1;
106
	private static final int IDX_REMOVE = 2;
107
108
	private ListDialogField fTodoTasksList;
109
	private Button fCaseSensitiveCheckbox;
110
111
	private final TodoTaskPreferences preferences;
112
113
	public TodoTaskConfigurationBlock(Preferences preferences,
114
			OverlayPreferenceStore store, PreferencePage mainPreferencePage) {
115
		super(store, mainPreferencePage);
116
		this.preferences = new TodoTaskPreferences(preferences);
117
		store.addKeys(createKeys());
118
	}
119
120
	private OverlayKey[] createKeys() {
121
		return new OverlayPreferenceStore.OverlayKey[] {
122
				new OverlayPreferenceStore.OverlayKey(
123
						OverlayPreferenceStore.STRING, TodoTaskPreferences.TAGS),
124
				new OverlayPreferenceStore.OverlayKey(
125
						OverlayPreferenceStore.BOOLEAN,
126
						TodoTaskPreferences.ENABLED),
127
				new OverlayPreferenceStore.OverlayKey(
128
						OverlayPreferenceStore.BOOLEAN,
129
						TodoTaskPreferences.CASE_SENSITIVE) };
130
	}
131
132
	public class TaskTagAdapter implements IListAdapter, IDialogFieldListener {
133
134
		private boolean canEdit(List selectedElements) {
135
			return selectedElements.size() == 1;
136
		}
137
138
		public void customButtonPressed(ListDialogField field, int index) {
139
			doTodoButtonPressed(index);
140
		}
141
142
		public void selectionChanged(ListDialogField field) {
143
			List selectedElements = field.getSelectedElements();
144
			field.enableButton(IDX_EDIT, canEdit(selectedElements));
145
		}
146
147
		public void doubleClicked(ListDialogField field) {
148
			if (canEdit(field.getSelectedElements())) {
149
				doTodoButtonPressed(IDX_EDIT);
150
			}
151
		}
152
153
		public void dialogFieldChanged(DialogField field) {
154
			updateModel(field);
155
		}
156
157
	}
158
159
	protected final void updateModel(DialogField field) {
160
		preferences.setTaskTags(fTodoTasksList.getElements());
161
	}
162
163
	private void doTodoButtonPressed(int index) {
164
		TodoTask edited = null;
165
		if (index != IDX_ADD) {
166
			edited = (TodoTask) fTodoTasksList.getSelectedElements().get(0);
167
		}
168
		if (index == IDX_ADD || index == IDX_EDIT) {
169
			TodoTaskInputDialog dialog = new TodoTaskInputDialog(getShell(),
170
					edited, fTodoTasksList.getElements());
171
			if (dialog.open() == Window.OK) {
172
				if (edited != null) {
173
					fTodoTasksList.replaceElement(edited, dialog.getResult());
174
				} else {
175
					fTodoTasksList.addElement(dialog.getResult());
176
				}
177
			}
178
		}
179
	}
180
181
	public Control createControl(Composite parent) {
182
		final TaskTagAdapter adapter = new TaskTagAdapter();
183
		final String[] buttons = new String[] {
184
				PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_add_button,
185
				PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_edit_button,
186
				PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_remove_button };
187
		fTodoTasksList = new ListDialogField(adapter, buttons,
188
				new TodoTaskLabelProvider());
189
		fTodoTasksList.setDialogFieldListener(adapter);
190
		fTodoTasksList.setRemoveButtonIndex(IDX_REMOVE);
191
192
		final String[] columnsHeaders = new String[] {
193
				PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_name_column,
194
				PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_priority_column, };
195
		fTodoTasksList.setTableColumns(new ListDialogField.ColumnsDescription(
196
				columnsHeaders, true));
197
		fTodoTasksList.setViewerSorter(new TodoTaskSorter());
198
199
		final GridLayout layout = new GridLayout();
200
		layout.marginHeight = 0;
201
		layout.marginWidth = 0;
202
		layout.numColumns = 2;
203
204
		final PixelConverter conv = new PixelConverter(parent);
205
206
		final Composite markersComposite = new Composite(parent, SWT.NULL);
207
		markersComposite.setLayout(layout);
208
		markersComposite.setFont(parent.getFont());
209
210
		final Button enableCheckbox = addCheckBox(markersComposite,
211
				"Enable task tags", TodoTaskPreferences.ENABLED, 0);
212
213
		fCaseSensitiveCheckbox = addCheckBox(
214
				markersComposite,
215
				PreferencesMessages.TodoTaskConfigurationBlock_casesensitive_label,
216
				TodoTaskPreferences.CASE_SENSITIVE, 0);
217
218
		final GridData data = new GridData(GridData.FILL_BOTH);
219
		data.widthHint = conv.convertWidthInCharsToPixels(50);
220
		fTodoTasksList.getListControl(markersComposite).setLayoutData(data);
221
222
		fTodoTasksList.getButtonBox(markersComposite).setLayoutData(
223
				new GridData(GridData.HORIZONTAL_ALIGN_FILL
224
						| GridData.VERTICAL_ALIGN_BEGINNING));
225
226
		enableCheckbox.addSelectionListener(new SelectionAdapter() {
227
228
			public void widgetSelected(SelectionEvent e) {
229
				final boolean enabled = ((Button) e.widget).getSelection();
230
				updateEnableState(enabled);
231
			}
232
233
		});
234
235
		return markersComposite;
236
	}
237
238
	protected void updateEnableState(boolean enabled) {
239
		fTodoTasksList.setEnabled(enabled);
240
		fCaseSensitiveCheckbox.setEnabled(enabled);
241
	}
242
243
	protected void initializeFields() {
244
		super.initializeFields();
245
		fTodoTasksList.setElements(preferences.getTaskTags());
246
		if (fTodoTasksList.getSize() > 0) {
247
			fTodoTasksList.selectFirstElement();
248
		} else {
249
			fTodoTasksList.enableButton(IDX_EDIT, false);
250
		}
251
		updateEnableState(preferences.isEnabled());
252
	}
253
254
}
(-)src/org/eclipse/dltk/ruby/internal/ui/preferences/RubyPreferencesMessages.java (+3 lines)
Lines 29-32 Link Here
29
	public static String EditorFoldingPreferencePageDescription;
29
	public static String EditorFoldingPreferencePageDescription;
30
30
31
	public static String GlobalPreferencePageDescription;
31
	public static String GlobalPreferencePageDescription;
32
33
	public static String TodoTaskDescription;
34
32
}
35
}
(-)src/org/eclipse/dltk/ruby/internal/ui/preferences/RubyPreferencesMessages.properties (+1 lines)
Lines 16-18 Link Here
16
16
17
GlobalPreferencePageDescription = General Ruby preferences
17
GlobalPreferencePageDescription = General Ruby preferences
18
18
19
TodoTaskDescription = Strings indicating tasks in Ruby comments.
(-)plugin.properties (+2 lines)
Lines 76-81 Link Here
76
RubyEditorFoldingPreferencePage.name = Folding
76
RubyEditorFoldingPreferencePage.name = Folding
77
RubyCodeTemplatesPreferencePage.name = Templates
77
RubyCodeTemplatesPreferencePage.name = Templates
78
78
79
RubyTaskTagsPreferencePage.name = Task Tags
80
79
# Decorators
81
# Decorators
80
RubyProjectDecorator.name = Ruby Project Decorator
82
RubyProjectDecorator.name = Ruby Project Decorator
81
83
(-)plugin.xml (+5 lines)
Lines 153-158 Link Here
153
              id="org.eclipse.dltk.ruby.preferences.templates"
153
              id="org.eclipse.dltk.ruby.preferences.templates"
154
              name="%RubyCodeTemplatesPreferencePage.name">
154
              name="%RubyCodeTemplatesPreferencePage.name">
155
     </page>	          
155
     </page>	          
156
      <page
157
              category="org.eclipse.dltk.ruby.preferences"
158
              class="org.eclipse.dltk.ruby.internal.ui.preferences.RubyTodoTaskPreferencePage"
159
              id="org.eclipse.dltk.ruby.preferences.todo"
160
              name="%RubyTaskTagsPreferencePage.name"/>
156
    </extension>
161
    </extension>
157
    
162
    
158
    <extension point="org.eclipse.ui.views">  
163
    <extension point="org.eclipse.ui.views">  
(-)src/org/eclipse/dltk/ruby/internal/ui/preferences/RubyTodoTaskPreferencePage.java (+32 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 xored software, Inc.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *     xored software, Inc. - initial API and Implementation (Alex Panchenko)
11
 *******************************************************************************/
12
package org.eclipse.dltk.ruby.internal.ui.preferences;
13
14
import org.eclipse.core.runtime.Preferences;
15
import org.eclipse.dltk.ruby.core.RubyPlugin;
16
import org.eclipse.dltk.ui.preferences.TodoTaskAbstractPreferencePage;
17
18
public class RubyTodoTaskPreferencePage extends TodoTaskAbstractPreferencePage {
19
20
	protected String getHelpId() {
21
		return null;
22
	}
23
24
	protected void setDescription() {
25
		setDescription(RubyPreferencesMessages.TodoTaskDescription);
26
	}
27
28
	protected Preferences getPluginPreferences() {
29
		return RubyPlugin.getDefault().getPluginPreferences();
30
	}
31
32
}
(-)src/org/eclipse/dltk/ruby/internal/parser/JRubySourceParser.java (-24 / +6 lines)
Lines 30-37 Link Here
30
import org.eclipse.dltk.ast.parser.AbstractSourceParser;
30
import org.eclipse.dltk.ast.parser.AbstractSourceParser;
31
import org.eclipse.dltk.ast.references.SimpleReference;
31
import org.eclipse.dltk.ast.references.SimpleReference;
32
import org.eclipse.dltk.ast.statements.Block;
32
import org.eclipse.dltk.ast.statements.Block;
33
import org.eclipse.dltk.compiler.problem.AbstractProblemReporter;
33
import org.eclipse.dltk.compiler.problem.IProblem;
34
import org.eclipse.dltk.compiler.problem.IProblem;
34
import org.eclipse.dltk.compiler.problem.IProblemReporter;
35
import org.eclipse.dltk.compiler.problem.IProblemReporter;
36
import org.eclipse.dltk.compiler.problem.ProblemReporterProxy;
35
import org.eclipse.dltk.core.DLTKCore;
37
import org.eclipse.dltk.core.DLTKCore;
36
import org.eclipse.dltk.ruby.core.RubyPlugin;
38
import org.eclipse.dltk.ruby.core.RubyPlugin;
37
import org.eclipse.dltk.ruby.core.utils.RubySyntaxUtils;
39
import org.eclipse.dltk.ruby.core.utils.RubySyntaxUtils;
Lines 272-303 Link Here
272
    return parserResult;
274
    return parserResult;
273
  }
275
  }
274
276
275
	private class ProxyProblemReporter implements IProblemReporter {
277
	private class ProxyProblemReporter extends ProblemReporterProxy {
276
277
		private final IProblemReporter original;
278
278
279
		public ProxyProblemReporter(IProblemReporter original) {
279
		public ProxyProblemReporter(IProblemReporter original) {
280
			super();
280
			super(original);
281
			this.original = original;
282
		}
281
		}
283
282
284
		public IMarker reportProblem(IProblem problem) throws CoreException {
283
		public IMarker reportProblem(IProblem problem) throws CoreException {
285
			IMarker m = null;
286
			if (original != null)
287
				m = original.reportProblem(problem);
288
			if (problem.isError()) {
284
			if (problem.isError()) {
289
				errorState[0] = true;
285
				errorState[0] = true;
290
			}
286
			}
291
			return m;
287
			return super.reportProblem(problem);
292
		}
293
294
		public void clearMarkers() {
295
			this.original.clearMarkers();
296
		}
288
		}
297
289
298
		public boolean isMarkersCleaned() {
299
			return original.isMarkersCleaned();
300
		}
301
	}
290
	}
302
	
291
	
303
	public JRubySourceParser() {
292
	public JRubySourceParser() {
Lines 513-519 Link Here
513
                    content2 = fixBrokenCommasUnsafe(content2);
502
                    content2 = fixBrokenCommasUnsafe(content2);
514
                    content2 = fixBrokenHashesUnsafe(content2);
503
                    content2 = fixBrokenHashesUnsafe(content2);
515
504
516
                    node2 = parser.parse("", new StringReader(content2), new IProblemReporter() { //$NON-NLS-1$
505
                    node2 = parser.parse("", new StringReader(content2), new AbstractProblemReporter() { //$NON-NLS-1$
517
506
518
                      public IMarker reportProblem(IProblem problem) {
507
                      public IMarker reportProblem(IProblem problem) {
519
                        if (DLTKCore.DEBUG) {
508
                        if (DLTKCore.DEBUG) {
Lines 529-541 Link Here
529
                        return null;
518
                        return null;
530
                      }
519
                      }
531
520
532
              		  public void clearMarkers() {
533
            		  }
534
535
              		  public boolean isMarkersCleaned() {
536
              			  return true;
537
              		  }
538
539
                    });
521
                    });
540
                    if (node2 != null)
522
                    if (node2 != null)
541
                      node = node2;
523
                      node = node2;
(-)src/org/eclipse/dltk/ruby/internal/parser/RubySourceElementParser.java (+17 lines)
Lines 10-17 Link Here
10
package org.eclipse.dltk.ruby.internal.parser;
10
package org.eclipse.dltk.ruby.internal.parser;
11
11
12
import org.eclipse.dltk.compiler.SourceElementRequestVisitor;
12
import org.eclipse.dltk.compiler.SourceElementRequestVisitor;
13
import org.eclipse.dltk.compiler.task.ITaskReporter;
14
import org.eclipse.dltk.compiler.task.TodoTaskPreferences;
15
import org.eclipse.dltk.compiler.task.TodoTaskSimpleParser;
13
import org.eclipse.dltk.core.AbstractSourceElementParser;
16
import org.eclipse.dltk.core.AbstractSourceElementParser;
14
import org.eclipse.dltk.ruby.core.RubyNature;
17
import org.eclipse.dltk.ruby.core.RubyNature;
18
import org.eclipse.dltk.ruby.core.RubyPlugin;
15
import org.eclipse.dltk.ruby.internal.parser.visitors.RubySourceElementRequestor;
19
import org.eclipse.dltk.ruby.internal.parser.visitors.RubySourceElementRequestor;
16
20
17
public class RubySourceElementParser extends AbstractSourceElementParser {
21
public class RubySourceElementParser extends AbstractSourceElementParser {
Lines 29-32 Link Here
29
	protected String getNatureId() {
33
	protected String getNatureId() {
30
		return RubyNature.NATURE_ID;
34
		return RubyNature.NATURE_ID;
31
	}
35
	}
36
37
	protected void parseTasks(ITaskReporter taskReporter, char[] content) {
38
		final TodoTaskPreferences preferences = new TodoTaskPreferences(
39
				RubyPlugin.getDefault().getPluginPreferences());
40
		if (preferences.isEnabled()) {
41
			final TodoTaskSimpleParser taskParser = new TodoTaskSimpleParser(
42
					taskReporter, preferences);
43
			if (taskParser.isValid()) {
44
				taskParser.parse(content);
45
			}
46
		}
47
	}
48
32
}
49
}
(-)src/org/eclipse/dltk/ruby/core/RubyPlugin.java (-1 / +3 lines)
Lines 16-21 Link Here
16
import org.eclipse.core.runtime.Plugin;
16
import org.eclipse.core.runtime.Plugin;
17
import org.eclipse.core.runtime.Status;
17
import org.eclipse.core.runtime.Status;
18
import org.eclipse.core.runtime.SubProgressMonitor;
18
import org.eclipse.core.runtime.SubProgressMonitor;
19
import org.eclipse.dltk.compiler.task.TodoTaskPreferences;
19
import org.eclipse.dltk.core.DLTKCore;
20
import org.eclipse.dltk.core.DLTKCore;
20
import org.eclipse.dltk.core.ModelException;
21
import org.eclipse.dltk.core.ModelException;
21
import org.eclipse.dltk.core.search.IDLTKSearchConstants;
22
import org.eclipse.dltk.core.search.IDLTKSearchConstants;
Lines 55-61 Link Here
55
	 * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
56
	 * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
56
	 */
57
	 */
57
	public void start(BundleContext context) throws Exception {
58
	public void start(BundleContext context) throws Exception {
58
		super.start(context);		
59
		super.start(context);
60
		new TodoTaskPreferences(getPluginPreferences()).initializeDefaultValues();
59
	}
61
	}
60
62
61
	/*
63
	/*
(-)plugin.xml (+5 lines)
Lines 239-244 Link Here
239
           id="org.eclipse.dltk.tcl.ui.assistance"
239
           id="org.eclipse.dltk.tcl.ui.assistance"
240
           name="%TclEditorAssistancePreferencePage.name">
240
           name="%TclEditorAssistancePreferencePage.name">
241
     </page>      
241
     </page>      
242
      <page
243
              category="org.eclipse.dltk.tcl.preferences"
244
              class="org.eclipse.dltk.tcl.internal.ui.preferences.TclTodoTaskPreferencePage"
245
              id="org.eclipse.dltk.tcl.preferences.todo"
246
              name="%TclTaskTagsPreferencePage.name"/>
242
          
247
          
243
 </extension>
248
 </extension>
244
 <extension
249
 <extension
(-)plugin.properties (+2 lines)
Lines 85-87 Link Here
85
85
86
OpenTypeInHierarchyAction.label=Open Type in Hierarch&y...
86
OpenTypeInHierarchyAction.label=Open Type in Hierarch&y...
87
OpenTypeInHierarchyAction.tooltip=Opens a Type in a Type Hierarchy
87
OpenTypeInHierarchyAction.tooltip=Opens a Type in a Type Hierarchy
88
89
TclTaskTagsPreferencePage.name = Task Tags
(-)src/org/eclipse/dltk/tcl/internal/ui/preferences/TclPreferencesMessages.properties (-2 / +1 lines)
Lines 19-23 Link Here
19
TCLSmartTypingConfigurationBlock_closeStrings ="Strings"
19
TCLSmartTypingConfigurationBlock_closeStrings ="Strings"
20
TCLSmartTypingConfigurationBlock_typing_tabTitle =TCLSmartTypingConfigurationBlock_typing_tabTitle
20
TCLSmartTypingConfigurationBlock_typing_tabTitle =TCLSmartTypingConfigurationBlock_typing_tabTitle
21
21
22
22
TodoTaskDescription = Strings indicating tasks in TCL comments.
23
(-)src/org/eclipse/dltk/tcl/internal/ui/preferences/TclPreferencesMessages.java (+1 lines)
Lines 24-27 Link Here
24
	public static String TCLSmartTypingConfigurationBlock_closeBraces;
24
	public static String TCLSmartTypingConfigurationBlock_closeBraces;
25
	public static String TCLSmartTypingConfigurationBlock_closeStrings;
25
	public static String TCLSmartTypingConfigurationBlock_closeStrings;
26
	public static String TCLSmartTypingConfigurationBlock_typing_tabTitle;
26
	public static String TCLSmartTypingConfigurationBlock_typing_tabTitle;
27
	public static String TodoTaskDescription;
27
}
28
}
(-)src/org/eclipse/dltk/tcl/internal/ui/preferences/TclTodoTaskPreferencePage.java (+32 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 xored software, Inc.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *     xored software, Inc. - initial API and Implementation (Alex Panchenko)
11
 *******************************************************************************/
12
package org.eclipse.dltk.tcl.internal.ui.preferences;
13
14
import org.eclipse.core.runtime.Preferences;
15
import org.eclipse.dltk.tcl.core.TclPlugin;
16
import org.eclipse.dltk.ui.preferences.TodoTaskAbstractPreferencePage;
17
18
public class TclTodoTaskPreferencePage extends TodoTaskAbstractPreferencePage {
19
20
	protected String getHelpId() {
21
		return null;
22
	}
23
24
	protected void setDescription() {
25
		setDescription(TclPreferencesMessages.TodoTaskDescription);
26
	}
27
28
	protected Preferences getPluginPreferences() {
29
		return TclPlugin.getDefault().getPluginPreferences();
30
	}
31
32
}
(-)model/org/eclipse/dltk/internal/core/AbstractSourceModule.java (-35 / +7 lines)
Lines 28-39 Link Here
28
import org.eclipse.dltk.core.ISourceElementParser;
28
import org.eclipse.dltk.core.ISourceElementParser;
29
import org.eclipse.dltk.core.ISourceElementParserExtension;
29
import org.eclipse.dltk.core.ISourceElementParserExtension;
30
import org.eclipse.dltk.core.ISourceModule;
30
import org.eclipse.dltk.core.ISourceModule;
31
import org.eclipse.dltk.core.ISourceModuleInfoCache;
32
import org.eclipse.dltk.core.ISourceRange;
31
import org.eclipse.dltk.core.ISourceRange;
33
import org.eclipse.dltk.core.IType;
32
import org.eclipse.dltk.core.IType;
34
import org.eclipse.dltk.core.ModelException;
33
import org.eclipse.dltk.core.ModelException;
34
import org.eclipse.dltk.core.SourceParserUtil;
35
import org.eclipse.dltk.core.WorkingCopyOwner;
35
import org.eclipse.dltk.core.WorkingCopyOwner;
36
import org.eclipse.dltk.core.ISourceModuleInfoCache.ISourceModuleInfo;
37
import org.eclipse.dltk.internal.core.util.MementoTokenizer;
36
import org.eclipse.dltk.internal.core.util.MementoTokenizer;
38
import org.eclipse.dltk.internal.core.util.Messages;
37
import org.eclipse.dltk.internal.core.util.Messages;
39
import org.eclipse.dltk.internal.core.util.Util;
38
import org.eclipse.dltk.internal.core.util.Util;
Lines 307-324 Link Here
307
	}
306
	}
308
307
309
	public String getSource() throws ModelException {
308
	public String getSource() throws ModelException {
310
		IBuffer buffer = getBufferNotOpen();
309
		final IBuffer buffer = getBufferNotOpen();
311
		if (buffer == null)
310
		return buffer != null ? buffer.getContents() : new String(
312
			return new String(getBufferContent()); //$NON-NLS-1$
311
				getBufferContent()); 
313
		return buffer.getContents();
314
	}
312
	}
315
313
316
	public char[] getSourceAsCharArray() throws ModelException {
314
	public char[] getSourceAsCharArray() throws ModelException {
317
		IBuffer buffer = getBufferNotOpen();
315
		final IBuffer buffer = getBufferNotOpen();
318
		if (buffer == null)
316
		return buffer != null ? buffer.getCharacters() : getBufferContent(); 
319
			return getBufferContent(); //$NON-NLS-1$
320
		return buffer.getContents().toCharArray();
321
		// return getSource().toCharArray();
322
	}
317
	}
323
318
324
	public String getSourceContents() {
319
	public String getSourceContents() {
Lines 446-465 Link Here
446
441
447
			SourceModuleElementInfo moduleInfo = (SourceModuleElementInfo) info;
442
			SourceModuleElementInfo moduleInfo = (SourceModuleElementInfo) info;
448
443
449
			// get buffer contents
450
			char[] contents;
451
			IBuffer buffer = getBufferManager().getBuffer(this);
452
			if (buffer != null) {
453
			  contents = buffer.getCharacters();
454
			}
455
			else {
456
			  //ssanders: PERFORMANCE - Avoid using a Buffer, if there isn't one already
457
			  contents = getBufferContent();
458
              //buffer = openBuffer(pm, moduleInfo); // open buffer
459
              // independently
460
              // from the info, since we are building the info
461
			}
462
463
			// generate structure and compute syntax problems if needed
444
			// generate structure and compute syntax problems if needed
464
			SourceModuleStructureRequestor requestor = new SourceModuleStructureRequestor(
445
			SourceModuleStructureRequestor requestor = new SourceModuleStructureRequestor(
465
					this, moduleInfo, newElements);
446
					this, moduleInfo, newElements);
Lines 483-498 Link Here
483
			parser.setRequestor(requestor);
464
			parser.setRequestor(requestor);
484
			parser.setReporter(problemReporter);
465
			parser.setReporter(problemReporter);
485
466
486
			/*
467
			SourceParserUtil.parseSourceModule(parser, this);
487
			 * XXX: this has performance problem written all over it if the user
488
			 * doesn't understand how the caching system works.
489
			 */
490
			ISourceModuleInfoCache sourceModuleInfoCache = ModelManager
491
					.getModelManager().getSourceModuleInfoCache();
492
			// sourceModuleInfoCache.remove(this);
493
			ISourceModuleInfo mifo = sourceModuleInfoCache.get(this);
494
			parser.parseSourceModule(contents, mifo, this.getPath().toString()
495
					.toCharArray());
496
468
497
			if (DEBUG_PRINT_MODEL) {
469
			if (DEBUG_PRINT_MODEL) {
498
				System.out.println("Source Module Debug print:"); //$NON-NLS-1$
470
				System.out.println("Source Module Debug print:"); //$NON-NLS-1$
(-)model/org/eclipse/dltk/internal/core/ModelElement.java (-2 / +1 lines)
Lines 17-23 Link Here
17
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.PlatformObject;
19
import org.eclipse.core.runtime.PlatformObject;
20
import org.eclipse.dltk.core.IScriptProject;
21
import org.eclipse.dltk.core.IField;
20
import org.eclipse.dltk.core.IField;
22
import org.eclipse.dltk.core.IModelElement;
21
import org.eclipse.dltk.core.IModelElement;
23
import org.eclipse.dltk.core.IModelElementVisitor;
22
import org.eclipse.dltk.core.IModelElementVisitor;
Lines 26-31 Link Here
26
import org.eclipse.dltk.core.IOpenable;
25
import org.eclipse.dltk.core.IOpenable;
27
import org.eclipse.dltk.core.IParent;
26
import org.eclipse.dltk.core.IParent;
28
import org.eclipse.dltk.core.IScriptModel;
27
import org.eclipse.dltk.core.IScriptModel;
28
import org.eclipse.dltk.core.IScriptProject;
29
import org.eclipse.dltk.core.ISourceModule;
29
import org.eclipse.dltk.core.ISourceModule;
30
import org.eclipse.dltk.core.ISourceRange;
30
import org.eclipse.dltk.core.ISourceRange;
31
import org.eclipse.dltk.core.ISourceReference;
31
import org.eclipse.dltk.core.ISourceReference;
Lines 36-42 Link Here
36
import org.eclipse.dltk.internal.core.util.MementoTokenizer;
36
import org.eclipse.dltk.internal.core.util.MementoTokenizer;
37
import org.eclipse.dltk.internal.core.util.Util;
37
import org.eclipse.dltk.internal.core.util.Util;
38
import org.eclipse.dltk.utils.CorePrinter;
38
import org.eclipse.dltk.utils.CorePrinter;
39
import org.omg.CORBA.Environment;
40
39
41
/**
40
/**
42
 * Root of model element handle hierarchy.
41
 * Root of model element handle hierarchy.
(-)model/org/eclipse/dltk/internal/core/SourceModuleInfoCache.java (-17 / +11 lines)
Lines 59-79 Link Here
59
		DLTKCore.removeElementChangedListener(changedListener);
59
		DLTKCore.removeElementChangedListener(changedListener);
60
	}
60
	}
61
61
62
	private final ISourceModuleInfo cacheGet(ISourceModule module) {
63
		allAccess++;
64
		final SoftReference ref = (SoftReference) cache.get(module);
65
		return ref != null ? (ISourceModuleInfo) ref.get() : null;
66
	}
67
62
	public ISourceModuleInfo get(ISourceModule module) {
68
	public ISourceModuleInfo get(ISourceModule module) {
63
		Object object = this.cache.get(module);
64
		if (DLTKCore.VERBOSE) {
69
		if (DLTKCore.VERBOSE) {
65
			System.out.println("Filling ratio:" + this.cache.fillingRatio()); //$NON-NLS-1$
70
			System.out.println("Filling ratio:" + this.cache.fillingRatio()); //$NON-NLS-1$
66
		}
71
		}
67
		allAccess++;
72
		ISourceModuleInfo info = cacheGet(module);
68
		if (object == null) {
69
			miss++;
70
			return returnAdd(module);
71
		}
72
		SoftReference ref = (SoftReference) object;
73
		ISourceModuleInfo info = (ISourceModuleInfo) ref.get();
74
		if (info == null) {
73
		if (info == null) {
75
			miss++;
74
			miss++;
76
			return returnAdd(module);
75
			info = new SourceModuleInfo();
76
			cache.put(module, new SoftReference(info));
77
			cache.ensureSpaceLimit(1, module);
78
			return info;
77
		}
79
		}
78
		// this.cache.printStats();
80
		// this.cache.printStats();
79
		if (DLTKCore.PERFOMANCE) {
81
		if (DLTKCore.PERFOMANCE) {
Lines 82-95 Link Here
82
					+ "% closes:" + closes); //$NON-NLS-1$
84
					+ "% closes:" + closes); //$NON-NLS-1$
83
			System.out.println("Filling ratio:" + this.cache.fillingRatio()); //$NON-NLS-1$
85
			System.out.println("Filling ratio:" + this.cache.fillingRatio()); //$NON-NLS-1$
84
		}
86
		}
85
		return (ISourceModuleInfo) info;
86
	}
87
88
	private ISourceModuleInfo returnAdd(ISourceModule module) {
89
		ISourceModuleInfo info = new SourceModuleInfo();
90
		SoftReference ref = new SoftReference(info);
91
		this.cache.put(module, ref);
92
		this.cache.ensureSpaceLimit(1, module);
93
		return info;
87
		return info;
94
	}
88
	}
95
89
(-)model/org/eclipse/dltk/internal/core/Openable.java (-8 / +6 lines)
Lines 220-236 Link Here
220
		}
220
		}
221
	}
221
	}
222
222
223
	/**
224
	 * Returns {@link IBuffer} or <code>null</code> if this element is not
225
	 * opened yet.
226
	 */
223
	public IBuffer getBufferNotOpen() throws ModelException {
227
	public IBuffer getBufferNotOpen() throws ModelException {
224
		if (hasBuffer()) {
228
		if (hasBuffer()) {
225
			// ensure element is open
229
			return getBufferManager().getBuffer(this);
226
			IBuffer buffer = getBufferManager().getBuffer(this);
227
			if (buffer == null) {
228
				return null;
229
			}
230
			return buffer;
231
		} else {
232
			return null;
233
		}
230
		}
231
		return null;
234
	}
232
	}
235
233
236
	/**
234
	/**
(-)compiler/org/eclipse/dltk/compiler/problem/DLTKProblemReporter.java (+9 lines)
Lines 12-17 Link Here
12
import org.eclipse.core.resources.IMarker;
12
import org.eclipse.core.resources.IMarker;
13
import org.eclipse.core.resources.IResource;
13
import org.eclipse.core.resources.IResource;
14
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.dltk.compiler.task.DLTKTaskReporter;
16
import org.eclipse.dltk.compiler.task.ITaskReporter;
15
import org.eclipse.dltk.core.DLTKCore;
17
import org.eclipse.dltk.core.DLTKCore;
16
18
17
public class DLTKProblemReporter implements IProblemReporter {
19
public class DLTKProblemReporter implements IProblemReporter {
Lines 97-100 Link Here
97
	public boolean isMarkersCleaned() {
99
	public boolean isMarkersCleaned() {
98
		return this.cleaned;
100
		return this.cleaned;
99
	}
101
	}
102
103
	public Object getAdapter(Class adapter) {
104
		if (ITaskReporter.class.equals(adapter)) {
105
			return new DLTKTaskReporter(resource);
106
		}
107
		return null;
108
	}
100
}
109
}
(-)compiler/org/eclipse/dltk/compiler/problem/IProblemReporter.java (-2 / +6 lines)
Lines 11-20 Link Here
11
11
12
import org.eclipse.core.resources.IMarker;
12
import org.eclipse.core.resources.IMarker;
13
import org.eclipse.core.runtime.CoreException;
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.IAdaptable;
15
16
public interface IProblemReporter extends IAdaptable {
14
17
15
public interface IProblemReporter {
16
	IMarker reportProblem(IProblem problem) throws CoreException;
18
	IMarker reportProblem(IProblem problem) throws CoreException;
17
	// Clear all existing markes from file
19
20
	// Clear all existing marks from file
18
	void clearMarkers();
21
	void clearMarkers();
22
19
	boolean isMarkersCleaned();
23
	boolean isMarkersCleaned();
20
}
24
}
(-)META-INF/MANIFEST.MF (-5 / +2 lines)
Lines 23-28 Link Here
23
 org.eclipse.dltk.compiler.env,
23
 org.eclipse.dltk.compiler.env,
24
 org.eclipse.dltk.compiler.env.lookup,
24
 org.eclipse.dltk.compiler.env.lookup,
25
 org.eclipse.dltk.compiler.problem,
25
 org.eclipse.dltk.compiler.problem,
26
 org.eclipse.dltk.compiler.task,
26
 org.eclipse.dltk.compiler.util,
27
 org.eclipse.dltk.compiler.util,
27
 org.eclipse.dltk.core,
28
 org.eclipse.dltk.core,
28
 org.eclipse.dltk.core.builder,
29
 org.eclipse.dltk.core.builder,
Lines 41-51 Link Here
41
 org.eclipse.dltk.internal.compiler.impl;x-internal:=true,
42
 org.eclipse.dltk.internal.compiler.impl;x-internal:=true,
42
 org.eclipse.dltk.internal.compiler.lookup;x-internal:=true,
43
 org.eclipse.dltk.internal.compiler.lookup;x-internal:=true,
43
 org.eclipse.dltk.internal.compiler.problem,
44
 org.eclipse.dltk.internal.compiler.problem,
44
 org.eclipse.dltk.internal.core;
45
 org.eclipse.dltk.internal.core;x-friends:="org.eclipse.dltk.ui,org.eclipse.dltk.launching,org.eclipse.dltk.debug,org.eclipse.dltk.validators.core",
45
  x-friends:="org.eclipse.dltk.ui,
46
   org.eclipse.dltk.launching,
47
   org.eclipse.dltk.debug,
48
   org.eclipse.dltk.validators.core",
49
 org.eclipse.dltk.internal.core.builder;x-internal:=true,
46
 org.eclipse.dltk.internal.core.builder;x-internal:=true,
50
 org.eclipse.dltk.internal.core.hierarchy,
47
 org.eclipse.dltk.internal.core.hierarchy,
51
 org.eclipse.dltk.internal.core.mixin,
48
 org.eclipse.dltk.internal.core.mixin,
(-)model/org/eclipse/dltk/core/SourceParserUtil.java (-86 / +117 lines)
Lines 9-129 Link Here
9
import org.eclipse.dltk.internal.core.ModelManager;
9
import org.eclipse.dltk.internal.core.ModelManager;
10
10
11
public class SourceParserUtil {
11
public class SourceParserUtil {
12
	private static final Object AST = "ast"; //$NON-NLS-1$
12
	private static final String AST = "ast"; //$NON-NLS-1$
13
	private static final Object FLAGS = "flags"; //$NON-NLS-1$
13
	private static final int DEFAULT_FLAGS = ISourceParserConstants.DEFAULT;
14
14
15
	/**
15
	/**
16
	 * Used to retrive module declaration from source module.
16
	 * Used to retrieve module declaration from source module.
17
	 */
17
	 */
18
	public static ModuleDeclaration getModuleDeclaration(ISourceModule module,
18
	public static ModuleDeclaration getModuleDeclaration(ISourceModule module,
19
			IProblemReporter reporter) {
19
			IProblemReporter reporter) {
20
		return getModuleDeclaration(module, reporter, ISourceParserConstants.DEFAULT);
20
		return getModuleDeclaration(module, reporter, DEFAULT_FLAGS);
21
	}
21
	}
22
22
	public static ModuleDeclaration getModuleDeclaration(ISourceModule module,
23
	public static ModuleDeclaration getModuleDeclaration(ISourceModule module,
23
			IProblemReporter reporter, int flags) {
24
			IProblemReporter reporter, int flags) {
24
		ISourceModuleInfoCache sourceModuleInfoCache = ModelManager
25
		ISourceModuleInfoCache cache = ModelManager.getModelManager()
25
				.getModelManager().getSourceModuleInfoCache();
26
				.getSourceModuleInfoCache();
26
		ISourceModuleInfo sourceModuleInfo = sourceModuleInfoCache.get(module);
27
		ISourceModuleInfo cacheEntry = cache.get(module);
27
		return getModuleDeclaration(module, reporter, sourceModuleInfo, flags);
28
		ModuleDeclaration declaration = getFromCache(cacheEntry, flags);
29
		if (declaration == null) {
30
			final char[] content = getModuleContent(module);
31
			if (content != null) {
32
				declaration = parseModule(module, content, reporter, flags);
33
				if (declaration != null) {
34
					putToCache(cacheEntry, declaration, flags);
35
				}
36
			}
37
		}
38
		return declaration;
39
	}
40
41
	private static ISourceParser getSourceParser(ISourceModule module) {
42
		IDLTKLanguageToolkit toolkit = DLTKLanguageManager
43
				.getLanguageToolkit(module);
44
		return DLTKLanguageManager.getSourceParser(toolkit.getNatureId());
45
	}
46
47
	private static String getCacheKey(int flags) {
48
		if (flags == DEFAULT_FLAGS) {
49
			return AST;
50
		} else {
51
			return AST + flags;
52
		}
28
	}
53
	}
29
54
30
	/**
55
	/**
31
	 * Used to retrive module declaration from source module.
56
	 * This is for use in parsers.
32
	 */
57
	 */
58
	private static ModuleDeclaration getFromCache(ISourceModuleInfo cacheEntry,
59
			int flags) {
60
		if (cacheEntry != null) {
61
			return (ModuleDeclaration) cacheEntry.get(getCacheKey(flags));
62
		}
63
		return null;
64
	}
33
65
34
	public static ModuleDeclaration getModuleDeclaration(ISourceModule module,
66
	private static void putToCache(ISourceModuleInfo cacheEntry,
35
			IProblemReporter reporter, ISourceModuleInfo mifo) {
67
			ModuleDeclaration declaration, int flags) {
36
		return getModuleDeclaration(module, reporter, mifo, ISourceParserConstants.DEFAULT);
68
		if (cacheEntry != null) {
69
			cacheEntry.put(getCacheKey(flags), declaration);
70
		}
37
	}
71
	}
38
	public static ModuleDeclaration getModuleDeclaration(ISourceModule module,
39
			IProblemReporter reporter, ISourceModuleInfo mifo, int flags) {
40
72
41
		IDLTKLanguageToolkit toolkit;
73
	private static char[] getModuleContent(ISourceModule module) {
42
		toolkit = DLTKLanguageManager.getLanguageToolkit(module);
74
		try {
43
		ModuleDeclaration moduleDeclaration = null;
75
			return module.getSourceAsCharArray();
44
		Integer flag;
76
		} catch (Exception e) {
45
		if (mifo != null) {
77
			DLTKCore.error("Error parsing " + module.getPath(), e);
46
			moduleDeclaration = (ModuleDeclaration) mifo.get(AST);
78
			return null;
47
			flag = (Integer) mifo.get(FLAGS);
48
			if( flag != null && flag.intValue() != flags ) {
49
				moduleDeclaration = null;
50
			}
51
		}
79
		}
52
		if (moduleDeclaration == null) {
80
	}
53
			if (reporter != null) {
81
54
				reporter.clearMarkers();
82
	private static ModuleDeclaration parseModule(ISourceModule module,
55
			}
83
			char[] content, IProblemReporter reporter, int flags) {
56
			ISourceParser sourceParser = null;
84
		if (reporter != null) {
57
			sourceParser = DLTKLanguageManager.getSourceParser(toolkit
85
			reporter.clearMarkers();
58
					.getNatureId());
86
		}
59
			if (sourceParser != null) {
87
		final ISourceParser parser = getSourceParser(module);
60
				if (sourceParser instanceof ISourceParserExtension) {
88
		if (parser instanceof ISourceParserExtension) {
61
					((ISourceParserExtension) sourceParser).setFlags(flags);
89
			((ISourceParserExtension) parser).setFlags(flags);
62
				}
63
				try {
64
					moduleDeclaration = sourceParser.parse(module.getPath()
65
							.toString().toCharArray(), module
66
							.getSourceAsCharArray(), reporter);
67
				} catch (ModelException e) {
68
					if (DLTKCore.DEBUG) {
69
						e.printStackTrace();
70
					}
71
				}
72
				if (moduleDeclaration != null && mifo != null) {
73
					mifo.put(AST, moduleDeclaration);
74
					mifo.put(FLAGS, new Integer(flags));
75
				}
76
			}
77
		}
90
		}
78
		return moduleDeclaration;
91
		final String filename = module.getPath().toString();
92
		return parser.parse(filename.toCharArray(), content, reporter);
79
	}
93
	}
80
94
81
	public static ModuleDeclaration getModuleDeclaration(char[] filename,
95
	public static void parseSourceModule(
82
			char[] content, String nature, IProblemReporter reporter,
96
			ISourceElementParser sourceElementParser, ISourceModule sourceModule) {
83
			ISourceModuleInfo mifo) {
97
		final ISourceModuleInfo cacheEntry = ModelManager.getModelManager()
84
		return getModuleDeclaration(filename, content, nature, reporter, mifo,
98
				.getSourceModuleInfoCache().get(sourceModule);
85
				ISourceParserConstants.DEFAULT);
99
		parseSourceModule(sourceElementParser, sourceModule, cacheEntry);
86
	}
100
	}
87
101
88
	public static ModuleDeclaration getModuleDeclaration(char[] filename,
102
	public static void parseSourceModule(ISourceElementParser elementParser,
89
			char[] content, String nature, IProblemReporter reporter,
103
			ISourceModule module, ISourceModuleInfo cacheEntry) {
90
			ISourceModuleInfo mifo, int flags) {
104
		if (cacheEntry != null
91
		ISourceParser sourceParser;// = new SourceParser(this.fReporter);
105
				&& elementParser instanceof ISourceElementASTCachingParser) {
92
		sourceParser = DLTKLanguageManager.getSourceParser(nature);
106
			final ISourceElementASTCachingParser cachingParser = (ISourceElementASTCachingParser) elementParser;
93
		if (sourceParser instanceof ISourceParserExtension) {
107
			final int flags = DEFAULT_FLAGS;
94
			((ISourceParserExtension) sourceParser).setFlags(flags);
108
			ModuleDeclaration declaration = getFromCache(cacheEntry, flags);
95
		}
109
			if (declaration == null) {
96
		ModuleDeclaration moduleDeclaration = SourceParserUtil
110
				final char[] content = getModuleContent(module);
97
				.getModuleFromCache(mifo, flags);
111
				if (content == null) {
98
		if (moduleDeclaration == null) {
112
					return;
99
			if (reporter != null) {
113
				}
100
				reporter.clearMarkers();
114
				IProblemReporter reporter = cachingParser.getProblemReporter();
115
				declaration = parseModule(module, content, reporter, flags);
116
				if (declaration != null) {
117
					putToCache(cacheEntry, declaration, flags);
118
					cachingParser.processModule(module, declaration, content);
119
				}
120
			} else {
121
				cachingParser.processModule(module, declaration, null);
122
			}
123
		} else {
124
			final char[] content = getModuleContent(module);
125
			if (content == null) {
126
				return;
101
			}
127
			}
102
			moduleDeclaration = sourceParser.parse(filename, content, reporter);
128
			elementParser.parseSourceModule(content, cacheEntry, module
103
			SourceParserUtil.putModuleToCache(mifo, moduleDeclaration, flags);
129
					.getPath().toString().toCharArray());
104
		}
130
		}
105
		return moduleDeclaration;
106
	}
131
	}
107
132
108
	/**
133
	/**
109
	 * This is for use in parsers.
134
	 * @param filename
135
	 * @param content
136
	 * @param natureId
137
	 * @param object
138
	 * @param object2
139
	 * @param runtimeModel
140
	 * @return
110
	 */
141
	 */
111
	public static ModuleDeclaration getModuleFromCache(ISourceModuleInfo mifo, int flags) {
142
	public static ModuleDeclaration getModuleDeclaration(char[] filename,
112
		if (mifo != null) {
143
			char[] content, String natureId, IProblemReporter reporter,
113
			Integer flag = (Integer) mifo.get(FLAGS);
144
			ISourceModuleInfo cacheEntry, int flags) {
114
			if( flag != null && flag.intValue() != flags ) {
145
		ModuleDeclaration declaration = getFromCache(cacheEntry, flags);
115
				return null;
146
		if (declaration == null) {
147
			ISourceParser parser = DLTKLanguageManager
148
					.getSourceParser(natureId);
149
			if (parser instanceof ISourceParserExtension) {
150
				((ISourceParserExtension) parser).setFlags(flags);
151
			}
152
			declaration = parser.parse(filename, content, reporter);
153
			if (declaration != null) {
154
				putToCache(cacheEntry, declaration, flags);
116
			}
155
			}
117
			return (ModuleDeclaration) mifo.get(AST);
118
		}
156
		}
119
		return null;
157
		return declaration;
120
	}
158
	}
121
159
122
	public static void putModuleToCache(ISourceModuleInfo info,
123
			ModuleDeclaration module, int flags) {
124
		if (info != null) {
125
			info.put(AST, module);
126
			info.put(FLAGS, new Integer(flags));
127
		}
128
	}
129
}
160
}
(-)model/org/eclipse/dltk/core/AbstractSourceElementParser.java (-8 / +52 lines)
Lines 11-38 Link Here
11
package org.eclipse.dltk.core;
11
package org.eclipse.dltk.core;
12
12
13
import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
13
import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
14
import org.eclipse.dltk.ast.parser.ISourceParser;
15
import org.eclipse.dltk.ast.parser.ISourceParserConstants;
16
import org.eclipse.dltk.ast.parser.ISourceParserExtension;
14
import org.eclipse.dltk.compiler.ISourceElementRequestor;
17
import org.eclipse.dltk.compiler.ISourceElementRequestor;
15
import org.eclipse.dltk.compiler.SourceElementRequestVisitor;
18
import org.eclipse.dltk.compiler.SourceElementRequestVisitor;
16
import org.eclipse.dltk.compiler.problem.IProblemReporter;
19
import org.eclipse.dltk.compiler.problem.IProblemReporter;
20
import org.eclipse.dltk.compiler.task.ITaskReporter;
17
import org.eclipse.dltk.core.ISourceModuleInfoCache.ISourceModuleInfo;
21
import org.eclipse.dltk.core.ISourceModuleInfoCache.ISourceModuleInfo;
18
22
19
public abstract class AbstractSourceElementParser implements
23
public abstract class AbstractSourceElementParser implements
20
		ISourceElementParser {
24
		ISourceElementParser, ISourceElementASTCachingParser {
21
25
22
	private ISourceElementRequestor sourceElementRequestor = null;
26
	private ISourceElementRequestor sourceElementRequestor;
23
	private IProblemReporter problemReporter;
27
	private IProblemReporter problemReporter;
24
28
25
	public void parseSourceModule(char[] contents, ISourceModuleInfo astCache,
29
	public void parseSourceModule(char[] contents, ISourceModuleInfo astCache,
26
			char[] filename) {
30
			char[] filename) {
31
		final ModuleDeclaration declaration = parseSource(filename, contents);
32
		final SourceElementRequestVisitor requestor = createVisitor();
33
		traverse(declaration, requestor);
34
	}
27
35
28
		ModuleDeclaration moduleDeclaration = SourceParserUtil
36
	protected ModuleDeclaration parseSource(char[] filename, char[] content) {
29
				.getModuleDeclaration(filename, contents, getNatureId(),
37
		if (problemReporter != null) {
30
						problemReporter, astCache);
38
			problemReporter.clearMarkers();
39
		}
40
		final ISourceParser sourceParser = createSourceParser();
41
		if (sourceParser instanceof ISourceParserExtension) {
42
			((ISourceParserExtension) sourceParser)
43
					.setFlags(ISourceParserConstants.DEFAULT);
44
		}
45
		return sourceParser.parse(filename, content, problemReporter);
46
	}
31
47
32
		SourceElementRequestVisitor requestor = createVisitor();
48
	protected ISourceParser createSourceParser() {
49
		return DLTKLanguageManager.getSourceParser(getNatureId());
50
	}
51
52
	public void processModule(ISourceModule module,
53
			ModuleDeclaration declaration, char[] content) {
54
		final SourceElementRequestVisitor requestor = createVisitor();
55
		traverse(declaration, requestor);
56
		if (content != null) {
57
			parseTasks(content);
58
		}
59
	}
33
60
61
	protected void traverse(final ModuleDeclaration declaration,
62
			final SourceElementRequestVisitor requestor) {
34
		try {
63
		try {
35
			moduleDeclaration.traverse(requestor);
64
			declaration.traverse(requestor);
36
		} catch (Exception e) {
65
		} catch (Exception e) {
37
			if (DLTKCore.DEBUG) {
66
			if (DLTKCore.DEBUG) {
38
				e.printStackTrace();
67
				e.printStackTrace();
Lines 40-45 Link Here
40
		}
69
		}
41
	}
70
	}
42
71
72
	protected void parseTasks(char[] content) {
73
		if (problemReporter != null) {
74
			final ITaskReporter taskReporter = (ITaskReporter) problemReporter
75
					.getAdapter(ITaskReporter.class);
76
			if (taskReporter != null) {
77
				taskReporter.clearTasks();
78
				parseTasks(taskReporter, content);
79
			}
80
		}
81
	}
82
83
	protected void parseTasks(ITaskReporter taskReporter, char[] content) {
84
		// empty - should be overridden in descendants
85
	}
86
43
	public void setReporter(IProblemReporter reporter) {
87
	public void setReporter(IProblemReporter reporter) {
44
		this.problemReporter = reporter;
88
		this.problemReporter = reporter;
45
	}
89
	}
Lines 52-58 Link Here
52
		return sourceElementRequestor;
96
		return sourceElementRequestor;
53
	}
97
	}
54
98
55
	protected IProblemReporter getProblemReporter() {
99
	public IProblemReporter getProblemReporter() {
56
		return problemReporter;
100
		return problemReporter;
57
	}
101
	}
58
102
(-)model/org/eclipse/dltk/core/DLTKCore.java (+10 lines)
Lines 27-34 Link Here
27
import org.eclipse.core.runtime.IExtensionPoint;
27
import org.eclipse.core.runtime.IExtensionPoint;
28
import org.eclipse.core.runtime.IPath;
28
import org.eclipse.core.runtime.IPath;
29
import org.eclipse.core.runtime.IProgressMonitor;
29
import org.eclipse.core.runtime.IProgressMonitor;
30
import org.eclipse.core.runtime.IStatus;
30
import org.eclipse.core.runtime.Platform;
31
import org.eclipse.core.runtime.Platform;
31
import org.eclipse.core.runtime.Plugin;
32
import org.eclipse.core.runtime.Plugin;
33
import org.eclipse.core.runtime.Status;
32
import org.eclipse.core.runtime.jobs.ISchedulingRule;
34
import org.eclipse.core.runtime.jobs.ISchedulingRule;
33
import org.eclipse.dltk.internal.core.BatchOperation;
35
import org.eclipse.dltk.internal.core.BatchOperation;
34
import org.eclipse.dltk.internal.core.BuildpathAccessRule;
36
import org.eclipse.dltk.internal.core.BuildpathAccessRule;
Lines 1541-1545 Link Here
1541
	public static String[] getUserLibraryNames(IDLTKLanguageToolkit toolkit) {
1543
	public static String[] getUserLibraryNames(IDLTKLanguageToolkit toolkit) {
1542
		 return ModelManager.getUserLibraryManager().getUserLibraryNames(toolkit);
1544
		 return ModelManager.getUserLibraryManager().getUserLibraryNames(toolkit);
1543
	}
1545
	}
1546
1547
	public static void error(String message) {
1548
		plugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, message, null));
1549
	}
1550
	
1551
	public static void error(String message, Throwable t) {
1552
		plugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, message, t));
1553
	}
1544
	
1554
	
1545
}
1555
}
(-)compiler/org/eclipse/dltk/compiler/task/ITaskReporter.java (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 xored software, Inc.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *     xored software, Inc. - initial API and Implementation (Alex Panchenko)
11
 *******************************************************************************/
12
package org.eclipse.dltk.compiler.task;
13
14
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IAdaptable;
17
18
/**
19
 * The interface to create <i>tasks</i> for the attached resource. At any given
20
 * moment this object operates on single {@link IResource}.
21
 */
22
public interface ITaskReporter extends IAdaptable {
23
24
	/**
25
	 * Clears all tasks related to the attached resource.
26
	 */
27
	void clearTasks();
28
29
	/**
30
	 * Creates new task for the attached resource.
31
	 * 
32
	 * @param message
33
	 * @param lineNumber
34
	 * @param priority
35
	 * @param charStart
36
	 * @param charEnd
37
	 * @throws CoreException
38
	 */
39
	void reportTask(String message, int lineNumber, int priority,
40
			int charStart, int charEnd) throws CoreException;
41
42
}
(-)compiler/org/eclipse/dltk/compiler/task/TodoTaskSimpleParser.java (+156 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 xored software, Inc.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *     xored software, Inc. - initial API and Implementation (Alex Panchenko)
11
 *******************************************************************************/
12
package org.eclipse.dltk.compiler.task;
13
14
import java.util.List;
15
16
import org.eclipse.core.resources.IMarker;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.dltk.core.DLTKCore;
19
20
public class TodoTaskSimpleParser {
21
22
	private final ITaskReporter taskReporter;
23
	private final boolean caseSensitive;
24
	private final char[][] tags;
25
	private final int minTagLength;
26
	private final int[] priorities;
27
28
	public TodoTaskSimpleParser(ITaskReporter taskReporter,
29
			TodoTaskPreferences preferences) {
30
		this.taskReporter = taskReporter;
31
		this.caseSensitive = preferences.isCaseSensitive();
32
		final List tags = preferences.getTaskTags();
33
		if (!tags.isEmpty()) {
34
			final int tagCount = tags.size();
35
			this.tags = new char[tagCount][];
36
			this.priorities = new int[tagCount];
37
			int minTagLength = Integer.MAX_VALUE;
38
			for (int i = 0; i < tagCount; ++i) {
39
				final TodoTask task = (TodoTask) tags.get(i);
40
				String tagName = task.name;
41
				if (!caseSensitive) {
42
					tagName = tagName.toUpperCase();
43
				}
44
				if (tagName.length() < minTagLength) {
45
					minTagLength = tagName.length();
46
				}
47
				this.tags[i] = tagName.toCharArray();
48
				if (TodoTask.PRIORITY_HIGH.equals(task.priority)) {
49
					priorities[i] = IMarker.PRIORITY_HIGH;
50
				} else if (TodoTask.PRIORITY_LOW.equals(task.priority)) {
51
					priorities[i] = IMarker.PRIORITY_LOW;
52
				} else {
53
					priorities[i] = IMarker.PRIORITY_NORMAL;
54
				}
55
			}
56
			this.minTagLength = minTagLength;
57
		} else {
58
			this.tags = null;
59
			this.minTagLength = 0;
60
			this.priorities = null;
61
		}
62
	}
63
64
	public boolean isValid() {
65
		return tags != null && tags.length > 0;
66
	}
67
68
	private int lineNumber;
69
	private int contentPos;
70
	private int contentEnd;
71
72
	public void parse(char[] content) {
73
		lineNumber = 0;
74
		contentPos = 0;
75
		contentEnd = content.length;
76
		while (contentPos < contentEnd) {
77
			int begin = contentPos;
78
			final int end = findEndOfLine(content);
79
			if (begin < end) {
80
				begin = skipSpaces(content, begin, end);
81
				if (begin < end && content[begin] == '#') {
82
					++begin;
83
					begin = skipSpaces(content, begin, end);
84
					if (begin + minTagLength <= end) {
85
						processLine(content, begin, end);
86
					}
87
				}
88
			}
89
			++lineNumber;
90
		}
91
	}
92
93
	private final int skipSpaces(char[] content, int pos, final int end) {
94
		while (pos < end && Character.isWhitespace(content[pos])) {
95
			++pos;
96
		}
97
		return pos;
98
	}
99
100
	private void processLine(char[] content, int begin, final int end) {
101
		for (int i = 0; i < tags.length; ++i) {
102
			final char[] tag = tags[i];
103
			if (begin + tag.length < end
104
					&& Character.isWhitespace(content[begin + tag.length])
105
					|| begin + tag.length == end) {
106
				if (compareTag(content, begin, tag)) {
107
					final String msg = new String(content, begin, end - begin);
108
					try {
109
						taskReporter.reportTask(msg, lineNumber, priorities[i],
110
								begin, contentPos);
111
					} catch (CoreException e) {
112
						DLTKCore.error("Error in reportTask()", e);
113
					}
114
				}
115
			}
116
		}
117
	}
118
119
	private boolean compareTag(char[] content, int pos, final char[] tag) {
120
		if (caseSensitive) {
121
			for (int j = 0; j < tag.length; ++j) {
122
				if (content[pos + j] != tag[j]) {
123
					return false;
124
				}
125
			}
126
		} else {
127
			for (int j = 0; j < tag.length; ++j) {
128
				if (Character.toUpperCase(content[pos + j]) != tag[j]) {
129
					return false;
130
				}
131
			}
132
		}
133
		return true;
134
	}
135
136
	private int findEndOfLine(char[] content) {
137
		while (contentPos < contentEnd) {
138
			if (content[contentPos] == '\r') {
139
				final int endLine = contentPos;
140
				++contentPos;
141
				if (contentPos < contentEnd && content[contentPos] == '\n') {
142
					++contentPos;
143
				}
144
				return endLine;
145
			} else if (content[contentPos] == '\n') {
146
				final int endLine = contentPos;
147
				++contentPos;
148
				return endLine;
149
			} else {
150
				++contentPos;
151
			}
152
		}
153
		return contentPos;
154
	}
155
156
}
(-)model/org/eclipse/dltk/core/ISourceElementASTCachingParser.java (+46 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 xored software, Inc.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *     xored software, Inc. - initial API and Implementation (Alex Panchenko)
11
 *******************************************************************************/
12
package org.eclipse.dltk.core;
13
14
import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
15
import org.eclipse.dltk.ast.parser.ISourceParser;
16
import org.eclipse.dltk.compiler.problem.IProblemReporter;
17
18
/**
19
 * The optional interface to be implemented by {@link ISourceElementParser} if
20
 * operates on the AST model build by {@link ISourceParser} and wishes to share
21
 * AST cache.
22
 */
23
public interface ISourceElementASTCachingParser extends ISourceElementParser {
24
25
	/**
26
	 * @return
27
	 */
28
	IProblemReporter getProblemReporter();
29
30
	/**
31
	 * This entry to call when caching is used.
32
	 * 
33
	 * @param module
34
	 *            the {@link ISourceModule} being parsed
35
	 * @param declaration
36
	 *            the {@link ModuleDeclaration} parsed
37
	 * @param content
38
	 *            source module content if module was just parsed or
39
	 *            <code>null</code> if {@link ModuleDeclaration} was retrieved
40
	 *            from cache (if the module content is needed it could be
41
	 *            retrieved from {@link ISourceModule}).
42
	 */
43
	void processModule(ISourceModule module, ModuleDeclaration declaration,
44
			char[] content);
45
46
}
(-)compiler/org/eclipse/dltk/compiler/task/TodoTaskPreferences.java (+111 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 xored software, Inc.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *     xored software, Inc. - initial API and Implementation (Alex Panchenko)
11
 *******************************************************************************/
12
package org.eclipse.dltk.compiler.task;
13
14
import java.util.ArrayList;
15
import java.util.List;
16
import java.util.StringTokenizer;
17
18
import org.eclipse.core.runtime.Preferences;
19
import org.eclipse.dltk.core.DLTKCore;
20
21
public class TodoTaskPreferences {
22
23
	public static final String CASE_SENSITIVE = DLTKCore.PLUGIN_ID
24
			+ "tasks.case_sensitive"; //$NON-NLS-1$
25
	public static final String TAGS = DLTKCore.PLUGIN_ID + "tasks.tags"; //$NON-NLS-1$
26
	public static final String ENABLED = DLTKCore.PLUGIN_ID + "tasks.enabled"; //$NON-NLS-1$
27
28
	private static final String TAG_SEPARATOR = ","; //$NON-NLS-1$
29
	private static final String PRIORITY_SEPARATOR = ";"; //$NON-NLS-1$
30
31
	public static boolean isValidName(String newText) {
32
		return newText.indexOf(TAG_SEPARATOR.charAt(0)) < 0
33
				&& newText.indexOf(PRIORITY_SEPARATOR.charAt(0)) < 0;
34
	}
35
36
	private final Preferences store;
37
38
	public TodoTaskPreferences(Preferences store) {
39
		this.store = store;
40
	}
41
42
	protected String[] getTokens(String text, String separator) {
43
		final StringTokenizer tok = new StringTokenizer(text, separator);
44
		final int nTokens = tok.countTokens();
45
		final String[] res = new String[nTokens];
46
		for (int i = 0; i < res.length; i++) {
47
			res[i] = tok.nextToken().trim();
48
		}
49
		return res;
50
	}
51
52
	public boolean isEnabled() {
53
		return store.getBoolean(ENABLED);
54
	}
55
56
	public boolean isCaseSensitive() {
57
		return store.getBoolean(CASE_SENSITIVE);
58
	}
59
60
	public List getTaskTags() {
61
		final String tags = store.getString(TAGS);
62
		final String[] tagPairs = getTokens(tags, TAG_SEPARATOR);
63
		final List elements = new ArrayList();
64
		for (int i = 0; i < tagPairs.length; ++i) {
65
			final String[] values = getTokens(tagPairs[i], PRIORITY_SEPARATOR);
66
			final TodoTask task = new TodoTask();
67
			task.name = values[0];
68
			if (values.length == 2) {
69
				task.priority = values[1];
70
			} else {
71
				task.priority = TodoTask.PRIORITY_NORMAL;
72
			}
73
			elements.add(task);
74
		}
75
		return elements;
76
	}
77
78
	public void setTaskTags(List elements) {
79
		store.setValue(TAGS, encodeTaskTags(elements));
80
	}
81
82
	private String encodeTaskTags(List elements) {
83
		final StringBuffer sb = new StringBuffer();
84
		for (int i = 0; i < elements.size(); ++i) {
85
			final TodoTask task = (TodoTask) elements.get(i);
86
			if (i > 0) {
87
				sb.append(TAG_SEPARATOR);
88
			}
89
			sb.append(task.name);
90
			sb.append(PRIORITY_SEPARATOR);
91
			sb.append(task.priority);
92
		}
93
		final String string = sb.toString();
94
		return string;
95
	}
96
97
	public static List getDefaultTags() {
98
		final List defaultTags = new ArrayList();
99
		defaultTags.add(new TodoTask("TODO", TodoTask.PRIORITY_NORMAL)); //$NON-NLS-1$
100
		defaultTags.add(new TodoTask("FIXME", TodoTask.PRIORITY_HIGH)); //$NON-NLS-1$ 
101
		defaultTags.add(new TodoTask("XXX", TodoTask.PRIORITY_NORMAL)); //$NON-NLS-1$
102
		return defaultTags;
103
	}
104
105
	public void initializeDefaultValues() {
106
		store.setDefault(ENABLED, true);
107
		store.setDefault(CASE_SENSITIVE, true);
108
		store.setDefault(TAGS, encodeTaskTags(getDefaultTags()));
109
	}
110
111
}
(-)compiler/org/eclipse/dltk/compiler/problem/AbstractProblemReporter.java (+32 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 xored software, Inc.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *     xored software, Inc. - initial API and Implementation (Alex Panchenko)
11
 *******************************************************************************/
12
package org.eclipse.dltk.compiler.problem;
13
14
/**
15
 * The abstract implementation of {@link IProblemReporter} to simplify code in
16
 * tests, etc.
17
 */
18
public abstract class AbstractProblemReporter implements IProblemReporter {
19
20
	public void clearMarkers() {
21
		// empty
22
	}
23
24
	public boolean isMarkersCleaned() {
25
		return false;
26
	}
27
28
	public Object getAdapter(Class adapter) {
29
		return null;
30
	}
31
32
}
(-)compiler/org/eclipse/dltk/compiler/task/TodoTask.java (+31 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 xored software, Inc.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *     xored software, Inc. - initial API and Implementation (Alex Panchenko)
11
 *******************************************************************************/
12
package org.eclipse.dltk.compiler.task;
13
14
public class TodoTask {
15
	public static final String PRIORITY_NORMAL = "NORMAL"; //$NON-NLS-1$
16
	public static final String PRIORITY_LOW = "LOW"; //$NON-NLS-1$
17
	public static final String PRIORITY_HIGH = "HIGH"; //$NON-NLS-1$
18
19
	public TodoTask() {
20
		// empty
21
	}
22
23
	public TodoTask(String name, String priority) {
24
		this.name = name;
25
		this.priority = priority;
26
	}
27
28
	public String name;
29
	public String priority;
30
31
}
(-)compiler/org/eclipse/dltk/compiler/task/DLTKTaskReporter.java (+58 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 xored software, Inc.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *     xored software, Inc. - initial API and Implementation (Alex Panchenko)
11
 *******************************************************************************/
12
package org.eclipse.dltk.compiler.task;
13
14
import org.eclipse.core.resources.IMarker;
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.runtime.CoreException;
17
18
/**
19
 * Default implementation of the {@link ITaskReporter}
20
 */
21
public class DLTKTaskReporter implements ITaskReporter {
22
23
	private final IResource resource;
24
	private boolean tasksCleared;
25
26
	public DLTKTaskReporter(IResource resource) {
27
		this.resource = resource;
28
		tasksCleared = false;
29
	}
30
31
	public void clearTasks() {
32
		if (!tasksCleared) {
33
			try {
34
				resource.deleteMarkers(IMarker.TASK, true,
35
						IResource.DEPTH_INFINITE);
36
			} catch (CoreException e) {
37
				System.err.println(e);
38
			}
39
			tasksCleared = true;
40
		}
41
	}
42
43
	public void reportTask(String message, int lineNumber, int priority,
44
			int charStart, int charEnd) throws CoreException {
45
		IMarker m = resource.createMarker(IMarker.TASK);
46
		m.setAttribute(IMarker.LINE_NUMBER, lineNumber + 1);
47
		m.setAttribute(IMarker.MESSAGE, message);
48
		m.setAttribute(IMarker.PRIORITY, priority);
49
		m.setAttribute(IMarker.CHAR_START, charStart);
50
		m.setAttribute(IMarker.CHAR_END, charEnd);
51
		m.setAttribute(IMarker.USER_EDITABLE, Boolean.FALSE);
52
	}
53
54
	public Object getAdapter(Class adapter) {
55
		return null;
56
	}
57
58
}
(-)compiler/org/eclipse/dltk/compiler/problem/ProblemReporterProxy.java (+56 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 xored software, Inc.
3
 *
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *     xored software, Inc. - initial API and Implementation (Alex Panchenko)
11
 *******************************************************************************/
12
package org.eclipse.dltk.compiler.problem;
13
14
import org.eclipse.core.resources.IMarker;
15
import org.eclipse.core.runtime.CoreException;
16
17
/**
18
 * The {@link IProblemReporter} implementation which forwards all methods call
19
 * to the instance passed in the constructor.
20
 */
21
public class ProblemReporterProxy implements IProblemReporter {
22
23
	private final IProblemReporter original;
24
25
	/**
26
	 * @param original
27
	 */
28
	protected ProblemReporterProxy(IProblemReporter original) {
29
		this.original = original;
30
	}
31
32
	public void clearMarkers() {
33
		if (original != null) {
34
			original.clearMarkers();
35
		}
36
	}
37
38
	public boolean isMarkersCleaned() {
39
		return original != null && original.isMarkersCleaned();
40
	}
41
42
	public IMarker reportProblem(IProblem problem) throws CoreException {
43
		if (original != null) {
44
			return original.reportProblem(problem);
45
		}
46
		return null;
47
	}
48
49
	public Object getAdapter(Class adapter) {
50
		if (original != null) {
51
			return original.getAdapter(adapter);
52
		}
53
		return null;
54
	}
55
56
}
(-)src/org/eclipse/dltk/ruby/core/tests/parser/AbstractASTTest.java (-8 / +2 lines)
Lines 14-21 Link Here
14
import org.eclipse.dltk.ast.ASTNode;
14
import org.eclipse.dltk.ast.ASTNode;
15
import org.eclipse.dltk.ast.ASTVisitor;
15
import org.eclipse.dltk.ast.ASTVisitor;
16
import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
16
import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
17
import org.eclipse.dltk.compiler.problem.AbstractProblemReporter;
17
import org.eclipse.dltk.compiler.problem.IProblem;
18
import org.eclipse.dltk.compiler.problem.IProblem;
18
import org.eclipse.dltk.compiler.problem.IProblemReporter;
19
import org.eclipse.dltk.core.DLTKLanguageManager;
19
import org.eclipse.dltk.core.DLTKLanguageManager;
20
import org.eclipse.dltk.core.tests.model.AbstractModelTests;
20
import org.eclipse.dltk.core.tests.model.AbstractModelTests;
21
import org.eclipse.dltk.ruby.core.RubyNature;
21
import org.eclipse.dltk.ruby.core.RubyNature;
Lines 23-29 Link Here
23
23
24
public abstract class AbstractASTTest extends AbstractModelTests {
24
public abstract class AbstractASTTest extends AbstractModelTests {
25
25
26
	protected static class CountingProblemReporter implements IProblemReporter {
26
	protected static class CountingProblemReporter extends AbstractProblemReporter {
27
27
28
		public int count = 0;
28
		public int count = 0;
29
		public String lastInfo = "<no errors>";
29
		public String lastInfo = "<no errors>";
Lines 46-57 Link Here
46
			return null;
46
			return null;
47
		}
47
		}
48
48
49
		public void clearMarkers() {
50
		}
51
52
		public boolean isMarkersCleaned() {
53
			return false;
54
		}
55
	}
49
	}
56
50
57
	protected final static CountingProblemReporter problems = new CountingProblemReporter();
51
	protected final static CountingProblemReporter problems = new CountingProblemReporter();

Return to bug 185488