KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > correction > ResolutionGenerator


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.pde.internal.ui.correction;
12
13 import org.eclipse.core.resources.IMarker;
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.pde.internal.core.ICoreConstants;
16 import org.eclipse.pde.internal.core.builders.PDEMarkerFactory;
17 import org.eclipse.ui.IMarkerResolution;
18 import org.eclipse.ui.IMarkerResolutionGenerator2;
19 import org.osgi.framework.Constants;
20
21 public class ResolutionGenerator implements IMarkerResolutionGenerator2 {
22     
23     private static IMarkerResolution[] NO_RESOLUTIONS = new IMarkerResolution[0];
24
25     /*
26      * (non-Javadoc)
27      * @see org.eclipse.ui.IMarkerResolutionGenerator#getResolutions(org.eclipse.core.resources.IMarker)
28      */

29     public IMarkerResolution[] getResolutions(IMarker marker) {
30         int problemID = marker.getAttribute("id", PDEMarkerFactory.NO_RESOLUTION); //$NON-NLS-1$
31
switch (problemID) {
32             case PDEMarkerFactory.M_DEPRECATED_AUTOSTART:
33                 return new IMarkerResolution[] {new RenameAutostartResolution(AbstractPDEMarkerResolution.RENAME_TYPE)};
34             case PDEMarkerFactory.M_JAVA_PACKAGE__PORTED:
35                 return new IMarkerResolution[] {new CreateJREBundleHeaderResolution(AbstractPDEMarkerResolution.CREATE_TYPE)};
36             case PDEMarkerFactory.M_SINGLETON_DIR_NOT_SET:
37                 return new IMarkerResolution[] {new AddSingletonToSymbolicName(AbstractPDEMarkerResolution.RENAME_TYPE, true)};
38             case PDEMarkerFactory.M_SINGLETON_ATT_NOT_SET:
39                 return new IMarkerResolution[] {new AddSingletonToSymbolicName(AbstractPDEMarkerResolution.RENAME_TYPE, false)};
40             case PDEMarkerFactory.M_SINGLETON_DIR_NOT_SUPPORTED:
41                 return new IMarkerResolution[] {new UnsupportedSingletonDirectiveResolution(AbstractPDEMarkerResolution.RENAME_TYPE)};
42             case PDEMarkerFactory.M_PROJECT_BUILD_ORDER_ENTRIES:
43                 return new IMarkerResolution[] {new RemoveStaticProjectReferences(AbstractPDEMarkerResolution.REMOVE_TYPE)};
44             case PDEMarkerFactory.M_EXPORT_PKG_NOT_EXIST:
45                 return getUnresolvedExportProposals(marker);
46             case PDEMarkerFactory.M_IMPORT_PKG_NOT_AVAILABLE:
47                 return getUnresolvedImportPackageProposals(marker);
48             case PDEMarkerFactory.M_REQ_BUNDLE_NOT_AVAILABLE:
49                 return getUnresolvedBundle(marker);
50             case PDEMarkerFactory.M_UNKNOWN_ACTIVATOR:
51                 return new IMarkerResolution[] {
52                         new CreateManifestClassResolution(AbstractPDEMarkerResolution.CREATE_TYPE, Constants.BUNDLE_ACTIVATOR),
53                         new ChooseManifestClassResolution(AbstractPDEMarkerResolution.RENAME_TYPE, Constants.BUNDLE_ACTIVATOR)};
54             case PDEMarkerFactory.M_UNKNOWN_CLASS:
55                 return new IMarkerResolution[] {
56                         new CreateManifestClassResolution(AbstractPDEMarkerResolution.CREATE_TYPE, ICoreConstants.PLUGIN_CLASS),
57                         new ChooseManifestClassResolution(AbstractPDEMarkerResolution.RENAME_TYPE, ICoreConstants.PLUGIN_CLASS)};
58             case PDEMarkerFactory.M_DIRECTIVE_HAS_NO_EFFECT:
59                 return getRemoveInternalDirectiveResolution(marker);
60             case PDEMarkerFactory.M_MISMATCHED_EXEC_ENV:
61                 return new IMarkerResolution[] { new UpdateClasspathResolution(AbstractPDEMarkerResolution.RENAME_TYPE)};
62             case PDEMarkerFactory.M_UNKNOW_EXEC_ENV:
63                 return new IMarkerResolution[] { new RemoveUnknownExecEnvironments(AbstractPDEMarkerResolution.REMOVE_TYPE)};
64             case PDEMarkerFactory.M_DEPRECATED_IMPORT_SERVICE:
65                 return new IMarkerResolution[] { new RemoveImportExportServicesResolution(AbstractPDEMarkerResolution.REMOVE_TYPE, ICoreConstants.IMPORT_SERVICE)};
66             case PDEMarkerFactory.M_DEPRECATED_EXPORT_SERVICE:
67                 return new IMarkerResolution[] { new RemoveImportExportServicesResolution(AbstractPDEMarkerResolution.REMOVE_TYPE, ICoreConstants.EXPORT_SERVICE)};
68             case PDEMarkerFactory.M_UNECESSARY_DEP:
69                 return new IMarkerResolution[] {new RemoveRequireBundleResolution(AbstractPDEMarkerResolution.REMOVE_TYPE, marker.getAttribute("bundleId", null))}; //$NON-NLS-1$
70
case PDEMarkerFactory.M_MISSING_EXPORT_PKGS:
71                 return new IMarkerResolution[] {new AddExportPackageMarkerResolution(AbstractPDEMarkerResolution.CREATE_TYPE, marker.getAttribute("packages", null))}; //$NON-NLS-1$
72
case PDEMarkerFactory.B_REMOVE_SLASH_FILE_ENTRY:
73                 return new IMarkerResolution[] { new RemoveSeperatorBuildEntryResolution(AbstractPDEMarkerResolution.RENAME_TYPE, marker)};
74             case PDEMarkerFactory.B_APPEND_SLASH_FOLDER_ENTRY:
75                 return new IMarkerResolution[] { new AppendSeperatorBuildEntryResolution(AbstractPDEMarkerResolution.RENAME_TYPE, marker)};
76             case PDEMarkerFactory.B_ADDDITION:
77                 return new IMarkerResolution[] { new AddBuildEntryResolution(AbstractPDEMarkerResolution.CREATE_TYPE, marker)};
78             case PDEMarkerFactory.B_SOURCE_ADDITION:
79                 return new IMarkerResolution[] { new AddSourceBuildEntryResolution(AbstractPDEMarkerResolution.CREATE_TYPE, marker)};
80             case PDEMarkerFactory.B_REMOVAL:
81                 return new IMarkerResolution[] { new RemoveBuildEntryResolution(AbstractPDEMarkerResolution.REMOVE_TYPE, marker)};
82             case PDEMarkerFactory.P_ILLEGAL_XML_NODE:
83                 return new IMarkerResolution[] { new RemoveNodeXMLResolution(AbstractPDEMarkerResolution.REMOVE_TYPE, marker)};
84             case PDEMarkerFactory.P_UNTRANSLATED_NODE:
85                 return new IMarkerResolution[] {
86                         new ExternalizeResolution(AbstractPDEMarkerResolution.RENAME_TYPE, marker),
87                         new ExternalizeStringsResolution(AbstractPDEMarkerResolution.RENAME_TYPE)};
88             case PDEMarkerFactory.P_UNKNOWN_CLASS:
89                 return new IMarkerResolution[] {
90                         new CreateClassXMLResolution(AbstractPDEMarkerResolution.CREATE_TYPE, marker),
91                         new ChooseClassXMLResolution(AbstractPDEMarkerResolution.RENAME_TYPE, marker)};
92         }
93         return NO_RESOLUTIONS;
94     }
95     
96     private IMarkerResolution[] getRemoveInternalDirectiveResolution(IMarker marker) {
97         String JavaDoc packageName = marker.getAttribute("packageName", (String JavaDoc)null); //$NON-NLS-1$
98
if (packageName != null) {
99             IResource res = marker.getResource();
100             if (res != null)
101                 return new IMarkerResolution[] {
102                         new RemoveInternalDirectiveEntryResolution(AbstractPDEMarkerResolution.REMOVE_TYPE, packageName)
103                     };
104         }
105         return NO_RESOLUTIONS;
106     }
107     
108     private IMarkerResolution[] getUnresolvedExportProposals(IMarker marker) {
109         String JavaDoc packageName = marker.getAttribute("packageName", (String JavaDoc)null); //$NON-NLS-1$
110
if (packageName != null) {
111             IResource res = marker.getResource();
112             if (res != null)
113                 return new IMarkerResolution[] {
114                         new RemoveExportPackageResolution(AbstractPDEMarkerResolution.REMOVE_TYPE, packageName)
115                     };
116         }
117         return NO_RESOLUTIONS;
118     }
119     
120     private IMarkerResolution[] getUnresolvedImportPackageProposals(IMarker marker) {
121         String JavaDoc packageName = marker.getAttribute("packageName", (String JavaDoc)null); //$NON-NLS-1$
122
if (packageName == null)
123             return NO_RESOLUTIONS;
124         
125         boolean optionalPkg = marker.getAttribute("optional", false); //$NON-NLS-1$
126
if (optionalPkg)
127             return new IMarkerResolution[] {new RemoveImportPackageResolution(AbstractPDEMarkerResolution.REMOVE_TYPE, packageName)};
128
129         return new IMarkerResolution[] {
130                 new RemoveImportPackageResolution(AbstractPDEMarkerResolution.REMOVE_TYPE, packageName),
131                 new OptionalImportPackageResolution(AbstractPDEMarkerResolution.RENAME_TYPE, packageName)
132             };
133     }
134     
135     private IMarkerResolution[] getUnresolvedBundle(IMarker marker) {
136         String JavaDoc bundleId = marker.getAttribute("bundleId", (String JavaDoc)null); //$NON-NLS-1$
137
if (bundleId == null)
138             return NO_RESOLUTIONS;
139         
140         boolean optionalBundle = marker.getAttribute("optional", false); //$NON-NLS-1$
141
if (optionalBundle)
142             return new IMarkerResolution[] {new RemoveRequireBundleResolution(AbstractPDEMarkerResolution.REMOVE_TYPE, bundleId)};
143
144 // IPreferenceStore store = PDEPlugin.getDefault().getPreferenceStore();
145
// boolean removeImports = store.getString(IPreferenceConstants.PROP_RESOLVE_IMPORTS).equals(IPreferenceConstants.VALUE_REMOVE_IMPORT);
146
return new IMarkerResolution[] {
147                 new RemoveRequireBundleResolution(AbstractPDEMarkerResolution.REMOVE_TYPE, bundleId),
148                 new OptionalRequireBundleResolution(AbstractPDEMarkerResolution.RENAME_TYPE, bundleId)
149 // new OrganizeRequireBundleResolution(AbstractPDEMarkerResolution.RENAME_TYPE, removeImports)
150
};
151     }
152
153     /*
154      * (non-Javadoc)
155      * @see org.eclipse.ui.IMarkerResolutionGenerator2#hasResolutions(org.eclipse.core.resources.IMarker)
156      */

157     public boolean hasResolutions(IMarker marker) {
158         return marker.getAttribute("id", PDEMarkerFactory.NO_RESOLUTION) > 0; //$NON-NLS-1$
159
}
160
161 }
162
Popular Tags