1 11 package org.eclipse.jdt.internal.corext.refactoring.participants; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.core.runtime.CoreException; 15 16 import org.eclipse.core.resources.IProject; 17 import org.eclipse.core.resources.IResource; 18 19 import org.eclipse.core.expressions.PropertyTester; 20 21 22 import org.eclipse.jdt.internal.ui.util.StringMatcher; 23 24 25 public class ResourceExtender extends PropertyTester { 26 27 private static final String PROPERTY_MATCHES_PATTERN= "matchesPattern"; private static final String PROJECT_NATURE = "projectNature"; private static final String CAN_DELETE= "canDelete"; 31 34 public boolean test(Object receiver, String method, Object [] args, Object expectedValue) { 35 IResource resource= (IResource)receiver; 36 if (PROPERTY_MATCHES_PATTERN.equals(method)) { 37 String fileName= resource.getName(); 38 StringMatcher matcher= new StringMatcher((String )expectedValue, false, false); 39 return matcher.match(fileName); 40 } else if (PROJECT_NATURE.equals(method)) { 41 try { 42 IProject proj = resource.getProject(); 43 return proj.isAccessible() && proj.hasNature((String )expectedValue); 44 } catch (CoreException e) { 45 return false; 46 } 47 } else if (CAN_DELETE.equals(method)) { 48 return canDelete(resource); 49 } 50 Assert.isTrue(false); 51 return false; 52 } 53 54 private boolean canDelete(IResource resource) { 55 if (!resource.exists() || resource.isPhantom()) 56 return false; 57 if (resource.getType() == IResource.ROOT || resource.getType() == IResource.PROJECT) 58 return false; 59 return true; 60 } 61 } 62 | Popular Tags |