Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: e3930ff99146e4a4e7154f9656e5b5f5703c0be8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*******************************************************************************
 * Copyright (c) 2001, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Jens Lukowski/Innoopract - initial renaming/restructuring
 *     
 *******************************************************************************/
package org.eclipse.wst.sse.core.internal.provisional.events;

import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;


/**
 * IStructuredDocument events are generated by the IStructuredDocument, after
 * the IStructuredDocument acts on a request. Not intended to be instantiated,
 * except by subclasses in infrastructure. Not intended to be subclassed by
 * clients.
 * 
 * @plannedfor 1.0
 */
public abstract class StructuredDocumentEvent extends DocumentEvent {
	private String fDeletedText;
	private Object fOriginalRequester;

	/**
	 * There is no public null-arg version of this constructor.
	 */
	private StructuredDocumentEvent() {
		super();
	}

	/**
	 * We assume (and require) that an IStructuredDocument's are always the
	 * source of StructuredDocument events.
	 * 
	 * @param document -
	 *            the document being changed
	 */
	private StructuredDocumentEvent(IStructuredDocument document) {
		this();
		if (document == null)
			throw new IllegalArgumentException("null source"); //$NON-NLS-1$
		fDocument = document;
		fOriginalRequester = document;
	}

	/**
	 * We assume (and require) that an IStructuredDocument's are always the
	 * source of StructuredDocument events.
	 * 
	 * @param document -
	 *            the document being changed.
	 * @param originalRequester -
	 *            the original requester of the change.
	 */
	StructuredDocumentEvent(IStructuredDocument document, Object originalRequester) {
		this(document);
		fOriginalRequester = originalRequester;
	}

	/**
	 * We assume (and require) that an IStructuredDocument's are always the
	 * source of StructuredDocument events.
	 * 
	 * @param document -
	 *            the document being changed.
	 * @param originalRequester -
	 *            the requester of the change.
	 * @param changes -
	 *            the String representing the new text
	 * @param offset -
	 *            the offset of the change.
	 * @param lengthToReplace -
	 *            the length of text to replace.
	 */
	StructuredDocumentEvent(IStructuredDocument document, Object originalRequester, String changes, int offset, int lengthToReplace) {
		this(document);
		fOriginalRequester = originalRequester;
		fText = changes;
		fOffset = offset;
		fLength = lengthToReplace;
	}

	/**
	 * Provides the text that is being deleted.
	 * 
	 * @return the text that is being deleted, or null if none is being
	 *         deleted.
	 */
	public String getDeletedText() {
		return fDeletedText;
	}

	/**
	 * This method returns the object that originally caused the event to
	 * fire. This is typically not the object that created the event (the
	 * IStructuredDocument) but instead the object that made a request to the
	 * IStructuredDocument.
	 * 
	 * @return the object that made the request to the document
	 */
	public Object getOriginalRequester() {
		return fOriginalRequester;
	}

	/**
	 * This method is equivalent to 'getDocument' except it returns an object
	 * of the appropriate type (namely, a IStructuredDocument, instead of
	 * IDocument).
	 * 
	 * @return IStructuredDocumnt - the document being changed
	 */
	public IStructuredDocument getStructuredDocument() {
		// a safe case, since constructor can only be called with a
		// IStructuredDocument
		return (IStructuredDocument) fDocument;
	}

	/**
	 * Not to be called by clients, only parsers and reparsers. (will
	 * eventually be moved to an SPI package).
	 * 
	 * @param newDeletedText -
	 *            the text that has been deleted.
	 */
	public void setDeletedText(String newDeletedText) {
		fDeletedText = newDeletedText;
	}

	/**
	 * for debugging only
	 * 
	 * @deprecated - need to fix unit tests which depend on this exact format,
	 *             then delete this
	 */
	public String toString() {
		// return getClass().getName() + "[source=" + source + "]";
		return getClass().getName();
	}
}

Back to the top