]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /*******************************************************************************\r |
2 | * Copyright (c) 2011, 2012 IBM Corporation and others.\r | |
3 | * All rights reserved. This program and the accompanying materials\r | |
4 | * are made available under the terms of the Eclipse Public License v1.0\r | |
5 | * which accompanies this distribution, and is available at\r | |
6 | * http://www.eclipse.org/legal/epl-v10.html\r | |
7 | *\r | |
8 | * Contributors:\r | |
9 | * IBM Corporation - initial API and implementation\r | |
10 | *******************************************************************************/\r | |
11 | package org.eclipse.jdt.internal.ui.text.correction.proposals;\r | |
12 | \r | |
13 | import org.eclipse.swt.graphics.Image;\r | |
14 | \r | |
15 | import org.eclipse.core.runtime.CoreException;\r | |
16 | import org.eclipse.core.runtime.IProgressMonitor;\r | |
17 | import org.eclipse.core.runtime.NullProgressMonitor;\r | |
18 | \r | |
19 | import org.eclipse.core.resources.IFile;\r | |
20 | \r | |
21 | import org.eclipse.text.edits.InsertEdit;\r | |
22 | \r | |
23 | import org.eclipse.ltk.core.refactoring.Refactoring;\r | |
24 | import org.eclipse.ltk.core.refactoring.RefactoringStatus;\r | |
25 | import org.eclipse.ltk.core.refactoring.TextChange;\r | |
26 | import org.eclipse.ltk.core.refactoring.TextFileChange;\r | |
27 | \r | |
28 | import org.eclipse.jdt.core.ICompilationUnit;\r | |
29 | \r | |
30 | \r | |
31 | public class RefactoringCorrectionProposal extends LinkedCorrectionProposal {\r | |
32 | private final Refactoring fRefactoring;\r | |
33 | private RefactoringStatus fRefactoringStatus;\r | |
34 | \r | |
35 | public RefactoringCorrectionProposal(String name, ICompilationUnit cu, Refactoring refactoring, int relevance, Image image) {\r | |
36 | super(name, cu, null, relevance, image);\r | |
37 | fRefactoring= refactoring;\r | |
38 | }\r | |
39 | \r | |
40 | /**\r | |
41 | * Can be overridden by clients to perform expensive initializations of the refactoring\r | |
42 | * \r | |
43 | * @param refactoring the refactoring\r | |
44 | * @throws CoreException if something goes wrong during init\r | |
45 | */\r | |
46 | protected void init(Refactoring refactoring) throws CoreException {\r | |
47 | // empty default implementation\r | |
48 | }\r | |
49 | \r | |
50 | @Override\r | |
51 | protected TextChange createTextChange() throws CoreException {\r | |
52 | init(fRefactoring);\r | |
53 | fRefactoringStatus= fRefactoring.checkFinalConditions(new NullProgressMonitor());\r | |
54 | if (fRefactoringStatus.hasFatalError()) {\r | |
55 | TextFileChange dummyChange= new TextFileChange("fatal error", (IFile) getCompilationUnit().getResource()); //$NON-NLS-1$\r | |
56 | dummyChange.setEdit(new InsertEdit(0, "")); //$NON-NLS-1$\r | |
57 | return dummyChange;\r | |
58 | }\r | |
59 | return (TextChange) fRefactoring.createChange(new NullProgressMonitor());\r | |
60 | }\r | |
61 | \r | |
62 | /*\r | |
63 | * @see org.eclipse.jdt.internal.ui.text.correction.proposals.CUCorrectionProposal#getAdditionalProposalInfo(org.eclipse.core.runtime.IProgressMonitor)\r | |
64 | * @since 3.6\r | |
65 | */\r | |
66 | @Override\r | |
67 | public Object getAdditionalProposalInfo(IProgressMonitor monitor) {\r | |
68 | if (fRefactoringStatus != null && fRefactoringStatus.hasFatalError()) {\r | |
69 | return fRefactoringStatus.getEntryWithHighestSeverity().getMessage();\r | |
70 | }\r | |
71 | return super.getAdditionalProposalInfo(monitor);\r | |
72 | }\r | |
73 | } |