1 11 package org.eclipse.pde.internal.ui.correction; 12 13 import org.eclipse.core.resources.IMarker; 14 import org.eclipse.core.resources.IProject; 15 import org.eclipse.osgi.util.NLS; 16 import org.eclipse.pde.core.plugin.IPluginExtension; 17 import org.eclipse.pde.core.plugin.IPluginModelBase; 18 import org.eclipse.pde.internal.core.PDECore; 19 import org.eclipse.pde.internal.core.ischema.ISchema; 20 import org.eclipse.pde.internal.core.ischema.ISchemaAttribute; 21 import org.eclipse.pde.internal.core.ischema.ISchemaElement; 22 import org.eclipse.pde.internal.core.schema.SchemaRegistry; 23 import org.eclipse.pde.internal.core.text.IDocumentNode; 24 import org.eclipse.pde.internal.core.text.plugin.PluginAttribute; 25 import org.eclipse.pde.internal.ui.PDEUIMessages; 26 import org.eclipse.pde.internal.ui.editor.plugin.JavaAttributeValue; 27 import org.eclipse.pde.internal.ui.util.PDEJavaHelperUI; 28 import org.eclipse.pde.internal.ui.util.TextUtil; 29 30 public class CreateClassXMLResolution extends AbstractXMLMarkerResolution { 31 32 public CreateClassXMLResolution(int resolutionType, IMarker marker) { 33 super(resolutionType, marker); 34 } 35 36 37 protected void createChange(IPluginModelBase model) { 39 Object object = findNode(model); 40 if (!(object instanceof PluginAttribute)) 41 return; 42 43 PluginAttribute attr = (PluginAttribute)object; 44 String name = TextUtil.trimNonAlphaChars(attr.getValue()).replace('$', '.'); 45 IProject project = model.getUnderlyingResource().getProject(); 46 47 JavaAttributeValue value = new JavaAttributeValue(project, model, getAttribute(attr), name); 48 name = PDEJavaHelperUI.createClass(name, project, value, true); 49 if (name != null && !name.equals(attr.getValue())) 50 attr.getEnclosingElement().setXMLAttribute(attr.getName(), name); 51 } 52 53 private ISchemaAttribute getAttribute(PluginAttribute attr) { 54 SchemaRegistry registry = PDECore.getDefault().getSchemaRegistry(); 55 IDocumentNode element = attr.getEnclosingElement(); 56 IPluginExtension extension = null; 57 while (element.getParentNode() != null) { 58 if (element instanceof IPluginExtension) { 59 extension = (IPluginExtension)element; 60 break; 61 } 62 element = element.getParentNode(); 63 } 64 if (extension == null) 65 return null; 66 67 ISchema schema = registry.getSchema(extension.getPoint()); 68 ISchemaElement schemaElement = schema.findElement(attr.getEnclosingElement().getXMLTagName()); 69 if (schemaElement == null) 70 return null; 71 return schemaElement.getAttribute(attr.getName()); 72 } 73 74 public String getLabel() { 75 return NLS.bind(PDEUIMessages.CreateClassXMLResolution_label, getNameOfNode()); 76 } 77 } 78 | Popular Tags |