1 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 29 public IMarkerResolution[] getResolutions(IMarker marker) { 30 int problemID = marker.getAttribute("id", PDEMarkerFactory.NO_RESOLUTION); 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))}; case PDEMarkerFactory.M_MISSING_EXPORT_PKGS: 71 return new IMarkerResolution[] {new AddExportPackageMarkerResolution(AbstractPDEMarkerResolution.CREATE_TYPE, marker.getAttribute("packages", null))}; 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 packageName = marker.getAttribute("packageName", (String )null); 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 packageName = marker.getAttribute("packageName", (String )null); 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 packageName = marker.getAttribute("packageName", (String )null); if (packageName == null) 123 return NO_RESOLUTIONS; 124 125 boolean optionalPkg = marker.getAttribute("optional", false); 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 bundleId = marker.getAttribute("bundleId", (String )null); if (bundleId == null) 138 return NO_RESOLUTIONS; 139 140 boolean optionalBundle = marker.getAttribute("optional", false); if (optionalBundle) 142 return new IMarkerResolution[] {new RemoveRequireBundleResolution(AbstractPDEMarkerResolution.REMOVE_TYPE, bundleId)}; 143 144 return new IMarkerResolution[] { 147 new RemoveRequireBundleResolution(AbstractPDEMarkerResolution.REMOVE_TYPE, bundleId), 148 new OptionalRequireBundleResolution(AbstractPDEMarkerResolution.RENAME_TYPE, bundleId) 149 }; 151 } 152 153 157 public boolean hasResolutions(IMarker marker) { 158 return marker.getAttribute("id", PDEMarkerFactory.NO_RESOLUTION) > 0; } 160 161 } 162 | Popular Tags |