KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > core > refactoring > TextChanges


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.ltk.internal.core.refactoring;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IPath;
15
16 import org.eclipse.core.filebuffers.FileBuffers;
17 import org.eclipse.core.filebuffers.ITextFileBuffer;
18 import org.eclipse.core.filebuffers.ITextFileBufferManager;
19 import org.eclipse.core.filebuffers.LocationKind;
20
21 import org.eclipse.core.resources.IFile;
22
23 import org.eclipse.jface.text.IDocument;
24
25 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
26
27 /**
28  * Helper class for text file changes.
29  */

30 public class TextChanges {
31     
32     private TextChanges() {
33         // no instance
34
}
35     
36     public static IDocument getDocument(IFile file) throws CoreException {
37         ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
38         IPath path= file.getFullPath();
39         ITextFileBuffer buffer= manager.getTextFileBuffer(path, LocationKind.IFILE);
40         if (buffer == null)
41             return null;
42         return buffer.getDocument();
43         
44     }
45     
46     public static RefactoringStatus isValid(IDocument document, int length) throws CoreException {
47         RefactoringStatus result= new RefactoringStatus();
48         if (length != document.getLength()) {
49             result.addFatalError(RefactoringCoreMessages.TextChanges_error_document_content_changed);
50         }
51         return result;
52     }
53 }
54
Popular Tags