KickJava   Java API By Example, From Geeks To Geeks.

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


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.ltk.internal.core.refactoring;
12
13 import org.eclipse.text.edits.MalformedTreeException;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Status;
18
19 import org.eclipse.core.resources.IFile;
20
21 import org.eclipse.jface.text.BadLocationException;
22
23 import org.eclipse.ltk.core.refactoring.IRefactoringCoreStatusCodes;
24 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
25
26 public class Changes {
27     
28     public static RefactoringStatus validateModifiesFiles(IFile[] filesToModify) {
29         RefactoringStatus result= new RefactoringStatus();
30         IStatus status= Resources.checkInSync(filesToModify);
31         if (!status.isOK())
32             result.merge(RefactoringStatus.create(status));
33         status= Resources.makeCommittable(filesToModify, null);
34         if (!status.isOK()) {
35             result.merge(RefactoringStatus.create(status));
36             if (!result.hasFatalError()) {
37                 result.addFatalError(RefactoringCoreMessages.Changes_validateEdit);
38             }
39         }
40         return result;
41     }
42     
43     public static RefactoringStatus checkInSync(IFile[] filesToModify) {
44         RefactoringStatus result= new RefactoringStatus();
45         IStatus status= Resources.checkInSync(filesToModify);
46         if (!status.isOK())
47             result.merge(RefactoringStatus.create(status));
48         return result;
49     }
50     
51     public static CoreException asCoreException(BadLocationException e) {
52         String JavaDoc message= e.getMessage();
53         if (message == null)
54             message= "BadLocationException"; //$NON-NLS-1$
55
return new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.BAD_LOCATION, message, e));
56     }
57     
58     public static CoreException asCoreException(MalformedTreeException e) {
59         String JavaDoc message= e.getMessage();
60         if (message == null)
61             message= "MalformedTreeException"; //$NON-NLS-1$
62
return new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.BAD_LOCATION, message, e));
63     }
64 }
65
Popular Tags