1 11 package org.eclipse.ltk.internal.core.refactoring; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.IConfigurationElement; 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.core.runtime.Status; 18 19 import org.eclipse.core.expressions.EvaluationResult; 20 import org.eclipse.core.expressions.Expression; 21 import org.eclipse.core.expressions.ExpressionConverter; 22 import org.eclipse.core.expressions.ExpressionTagNames; 23 import org.eclipse.core.expressions.IEvaluationContext; 24 25 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 26 27 import org.eclipse.ltk.core.refactoring.participants.IParticipantDescriptorFilter; 28 import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant; 29 30 public class ParticipantDescriptor { 31 32 private IConfigurationElement fConfigurationElement; 33 private boolean fEnabled; 34 35 private static final String ID= "id"; private static final String NAME= "name"; private static final String CLASS= "class"; private static final String PROCESS_ON_CANCEL= "processOnCancel"; 40 public ParticipantDescriptor(IConfigurationElement element) { 41 fConfigurationElement= element; 42 fEnabled= true; 43 } 44 45 public String getId() { 46 return fConfigurationElement.getAttribute(ID); 47 } 48 49 public String getName() { 50 return fConfigurationElement.getAttribute(NAME); 51 } 52 53 public IStatus checkSyntax() { 54 if (fConfigurationElement.getAttribute(ID) == null) { 55 return new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IStatus.ERROR, 56 RefactoringCoreMessages.ParticipantDescriptor_error_id_missing, null); 57 } 58 if (fConfigurationElement.getAttribute(NAME) == null) { 59 return new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IStatus.ERROR, 60 Messages.format( RefactoringCoreMessages.ParticipantDescriptor_error_name_missing, getId()), 61 null); 62 } 63 if (fConfigurationElement.getAttribute(CLASS) == null) { 64 return new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IStatus.ERROR, 65 Messages.format( RefactoringCoreMessages.ParticipantDescriptor_error_class_missing, getId()), 66 null); 67 } 68 return new Status(IStatus.OK, RefactoringCorePlugin.getPluginId(), IStatus.OK, 69 RefactoringCoreMessages.ParticipantDescriptor_correct, null); 70 } 71 72 public boolean matches(IEvaluationContext context, IParticipantDescriptorFilter filter, RefactoringStatus status) throws CoreException { 73 IConfigurationElement[] elements= fConfigurationElement.getChildren(ExpressionTagNames.ENABLEMENT); 74 if (elements.length == 0) 75 return false; 76 Assert.isTrue(elements.length == 1); 77 Expression exp= ExpressionConverter.getDefault().perform(elements[0]); 78 if (!convert(exp.evaluate(context))) 79 return false; 80 if (filter != null && !filter.select(fConfigurationElement, status)) 81 return false; 82 83 return true; 84 } 85 86 public RefactoringParticipant createParticipant() throws CoreException { 87 return (RefactoringParticipant)fConfigurationElement.createExecutableExtension(CLASS); 88 } 89 90 public boolean isEnabled() { 91 return fEnabled; 92 } 93 94 public void disable() { 95 fEnabled= false; 96 } 97 98 public boolean processOnCancel() { 99 String attr= fConfigurationElement.getAttribute(PROCESS_ON_CANCEL); 100 if (attr == null) 101 return false; 102 return Boolean.valueOf(attr).booleanValue(); 103 } 104 105 private boolean convert(EvaluationResult eval) { 106 if (eval == EvaluationResult.FALSE) 107 return false; 108 return true; 109 } 110 111 public String toString() { 112 return "name= " + getName() + (isEnabled() ? " (enabled)" : " (disabled)") + "\nid= " + getId() + "\nclass= " + fConfigurationElement.getAttribute(CLASS); } 116 } | Popular Tags |