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

Collapse All | Expand All

(-)src/org/eclipse/linuxtools/rpm/ui/editor/SpecfileCompletionProcessor.java (-3 / +3 lines)
Lines 253-265 Link Here
253
			if (elements.length == 0 || offset < elements[0].getLineEndPosition()) {
253
			if (elements.length == 0 || offset < elements[0].getLineEndPosition()) {
254
				return Activator.getDefault().getContextTypeRegistry()
254
				return Activator.getDefault().getContextTypeRegistry()
255
						.getContextType(PREAMBLE_SECTION_TEMPLATE);
255
						.getContextType(PREAMBLE_SECTION_TEMPLATE);
256
			} else if (offset < elements[1].getLineEndPosition()) {
256
			} else if (elements.length == 1 || offset < elements[1].getLineEndPosition()) {
257
				return Activator.getDefault().getContextTypeRegistry()
257
				return Activator.getDefault().getContextTypeRegistry()
258
						.getContextType(PRE_SECTION_TEMPLATE);
258
						.getContextType(PRE_SECTION_TEMPLATE);
259
			} else if (offset < elements[2].getLineEndPosition()) {
259
			} else if (elements.length == 2 || offset < elements[2].getLineEndPosition()) {
260
				return Activator.getDefault().getContextTypeRegistry()
260
				return Activator.getDefault().getContextTypeRegistry()
261
						.getContextType(BUILD_SECTION_TEMPLATE);
261
						.getContextType(BUILD_SECTION_TEMPLATE);
262
			} else if (offset < elements[3].getLineEndPosition()) {
262
			} else if (elements.length == 3 || offset < elements[3].getLineEndPosition()) {
263
				return Activator.getDefault().getContextTypeRegistry()
263
				return Activator.getDefault().getContextTypeRegistry()
264
						.getContextType(INSTALL_SECTION_TEMPLATE);
264
						.getContextType(INSTALL_SECTION_TEMPLATE);
265
			} else {
265
			} else {
(-)src/org/eclipse/linuxtools/rpm/ui/editor/SpecfileFoldingStructureProvider.java (-4 / +4 lines)
Lines 48-67 Link Here
48
		sDocument = document;
48
		sDocument = document;
49
	}
49
	}
50
50
51
	public void updateFoldingRegions(Specfile specfile) {
51
	public void updateFoldingRegions() {
52
		try {
52
		try {
53
			ProjectionAnnotationModel model = (ProjectionAnnotationModel) sEditor
53
			ProjectionAnnotationModel model = (ProjectionAnnotationModel) sEditor
54
					.getAdapter(ProjectionAnnotationModel.class);
54
					.getAdapter(ProjectionAnnotationModel.class);
55
			if (model != null)
55
			if (model != null)
56
				updateFoldingRegions(specfile, model);
56
				updateFoldingRegions(model);
57
		} catch (BadLocationException e) {
57
		} catch (BadLocationException e) {
58
			e.printStackTrace();
58
			e.printStackTrace();
59
		}
59
		}
60
	}
60
	}
61
61
62
	void updateFoldingRegions(Specfile specfile, ProjectionAnnotationModel model)
62
	void updateFoldingRegions(ProjectionAnnotationModel model)
63
			throws BadLocationException {
63
			throws BadLocationException {
64
		Set/* <Position> */structure = createFoldingStructure(specfile);
64
		Set/* <Position> */structure = createFoldingStructure(sEditor.getSpecfile());
65
		Annotation[] deletions = computeDifferences(model, structure);
65
		Annotation[] deletions = computeDifferences(model, structure);
66
		Map/* <Annotation,Position> */additions = computeAdditions(structure);
66
		Map/* <Annotation,Position> */additions = computeAdditions(structure);
67
		if ((deletions.length != 0 || additions.size() != 0)
67
		if ((deletions.length != 0 || additions.size() != 0)
(-)src/org/eclipse/linuxtools/rpm/ui/editor/SpecfileReconcilingStrategy.java (-23 / +19 lines)
Lines 8-21 Link Here
8
import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
8
import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
9
import org.eclipse.linuxtools.rpm.ui.editor.outline.SpecfileContentOutlinePage;
9
import org.eclipse.linuxtools.rpm.ui.editor.outline.SpecfileContentOutlinePage;
10
import org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile;
10
import org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile;
11
import org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser;
11
import org.eclipse.swt.widgets.Shell;
12
import org.eclipse.ui.texteditor.IDocumentProvider;
12
import org.eclipse.ui.texteditor.IDocumentProvider;
13
13
14
public class SpecfileReconcilingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension {
14
public class SpecfileReconcilingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension {
15
15
16
	private IDocument sDocument;
16
	private IDocument sDocument;
17
	private IProgressMonitor sProgressMonitor;
17
	private IProgressMonitor sProgressMonitor;
18
	private SpecfileParser sParser;
19
	private SpecfileFoldingStructureProvider sFoldingStructureProvider;
18
	private SpecfileFoldingStructureProvider sFoldingStructureProvider;
20
	
19
	
21
	SpecfileContentOutlinePage outline;
20
	SpecfileContentOutlinePage outline;
Lines 28-50 Link Here
28
		lastRegionOffset = Integer.MAX_VALUE;
27
		lastRegionOffset = Integer.MAX_VALUE;
29
		this.editor = editor;
28
		this.editor = editor;
30
		documentProvider = editor.getDocumentProvider();
29
		documentProvider = editor.getDocumentProvider();
31
		sParser= new SpecfileParser();
32
		sFoldingStructureProvider= new SpecfileFoldingStructureProvider(editor);
30
		sFoldingStructureProvider= new SpecfileFoldingStructureProvider(editor);
33
	}
31
	}
34
32
35
	public void reconcile(IRegion partition) {
36
		try {
37
			Specfile specfile = editor.getSpecfile();
38
			SpecfileParser parser = editor.getParser();
39
			if (specfile != null) {
40
				editor.setSpecfile(parser.parse(documentProvider
41
						.getDocument(editor.getEditorInput())));
42
				outline.update();
43
			}
44
		} catch (Exception e) {
45
			e.printStackTrace();
46
		}
47
	}
48
	
33
	
49
	public void setDocument(IDocument document) {
34
	public void setDocument(IDocument document) {
50
		sDocument= document;
35
		sDocument= document;
Lines 65-86 Link Here
65
	}
50
	}
66
51
67
	private void reconcile() {
52
	private void reconcile() {
68
		Specfile specfile= parseSpecfile();
53
		Specfile specfile = editor.getParser().parse(documentProvider
54
				.getDocument(editor.getEditorInput()));
69
		if (specfile != null) {
55
		if (specfile != null) {
70
			updateEditor(specfile);
56
			updateEditor(specfile);
71
			updateFolding(specfile);
57
			editor.setSpecfile(specfile);
58
			outline.update();
59
			updateFolding();
72
		}
60
		}
73
	}
61
	}
74
62
	
75
	private Specfile parseSpecfile() {
63
	public void reconcile(IRegion partition) {
76
		return sParser.parse(sDocument);
64
		reconcile();
77
	}
65
	}
78
66
79
	private void updateEditor(final Specfile specfile) {
67
	private void updateEditor(final Specfile specfile) {
68
		Shell shell= editor.getSite().getShell();
69
		if (!(shell == null || shell.isDisposed())) {
70
			shell.getDisplay().asyncExec(new Runnable() {
71
				public void run() {
72
					editor.setSpecfile(specfile);
73
				}
74
			});
75
		}
80
		return;
76
		return;
81
	}
77
	}
82
78
83
	private void updateFolding(Specfile specfile) {
79
	private void updateFolding() {
84
		sFoldingStructureProvider.updateFoldingRegions(specfile);
80
		sFoldingStructureProvider.updateFoldingRegions();
85
	}
81
	}
86
}
82
}
(-)src/org/eclipse/linuxtools/rpm/ui/editor/parser/SpecfileParser.java (-13 / +2 lines)
Lines 43-49 Link Here
43
	private SpecfileErrorHandler errorHandler;
43
	private SpecfileErrorHandler errorHandler;
44
44
45
	public Specfile parse(IDocument specfileDocument) {
45
	public Specfile parse(IDocument specfileDocument) {
46
46
		// remove all existing markers.
47
		errorHandler.removeExistingMarkers();
47
		LineNumberReader reader = new LineNumberReader(new StringReader(
48
		LineNumberReader reader = new LineNumberReader(new StringReader(
48
				specfileDocument.get()));
49
				specfileDocument.get()));
49
		String line = "";
50
		String line = "";
Lines 370-379 Link Here
370
					if (token.endsWith(":")) {
371
					if (token.endsWith(":")) {
371
						token = token.substring(0, token.length() - 1);
372
						token = token.substring(0, token.length() - 1);
372
					} else {
373
					} else {
373
						// FIXME: (al) Have not found why, but in some case errorHandler is null.
374
						// When this exception occurs, folding is not shown.
375
						// This fix work at less with the eclipse.spec and eclipse-mylar.spec file.
376
						if (errorHandler != null)
377
							// FIXME:  come up with a better error message here
374
							// FIXME:  come up with a better error message here
378
							// FIXME:  what about descriptions that begin a line with the word "Source" or "Patch"?
375
							// FIXME:  what about descriptions that begin a line with the word "Source" or "Patch"?
379
							errorHandler
376
							errorHandler
Lines 418-427 Link Here
418
					if (toReturn != null)
415
					if (toReturn != null)
419
						toReturn.setFileName(token);
416
						toReturn.setFileName(token);
420
					if (iter.hasNext()) {
417
					if (iter.hasNext()) {
421
						// FIXME: (al) Have not found why, but in some case errorHandler is null.
422
						// When this NullPointerException occurs, folding is not shown.
423
						// This fix works at least with the eclipse.spec and eclipse-mylar.spec.
424
						if (errorHandler != null)
425
							errorHandler.handleError(new SpecfileParseException(
418
							errorHandler.handleError(new SpecfileParseException(
426
									"Filename cannot be multiple words.",
419
									"Filename cannot be multiple words.",
427
									lineNumber, 0, lineText.length(),
420
									lineNumber, 0, lineText.length(),
Lines 456-465 Link Here
456
								IMarker.SEVERITY_ERROR));
449
								IMarker.SEVERITY_ERROR));
457
						return null;
450
						return null;
458
					} else {
451
					} else {
459
						// FIXME: (al) Have not found why, but in some case errorHandler is null.
460
						// When this NPE occurs, folding is not shown.
461
						// This fix works at least with the eclipse.spec and eclipse-mylar.spec
462
						if (errorHandler != null)
463
							errorHandler.handleError(new SpecfileParseException(
452
							errorHandler.handleError(new SpecfileParseException(
464
									token.substring(0, token.length() - 1) + " should be an acronym.",
453
									token.substring(0, token.length() - 1) + " should be an acronym.",
465
									lineNumber, 0, lineText.length(),
454
									lineNumber, 0, lineText.length(),

Return to bug 181110