1 11 package org.eclipse.jdt.internal.junit.launcher; 12 13 import org.eclipse.core.expressions.PropertyTester; 14 15 import org.eclipse.core.resources.IResource; 16 17 import org.eclipse.jdt.core.ICompilationUnit; 18 import org.eclipse.jdt.core.IJavaElement; 19 import org.eclipse.jdt.core.IType; 20 import org.eclipse.jdt.core.JavaCore; 21 import org.eclipse.jdt.core.JavaModelException; 22 import org.eclipse.jdt.core.Signature; 23 24 import org.eclipse.jdt.internal.junit.util.TestSearchEngine; 25 26 30 public class ResourceExtender extends PropertyTester { 31 32 private static final String PROPERTY_IS_TEST= "isTest"; 34 37 public boolean test(Object receiver, String method, Object [] args, Object expectedValue) { 38 IResource resource= (IResource)receiver; 39 if (PROPERTY_IS_TEST.equals(method)) { 40 return isJUnitTest(resource); 41 } 42 throw new IllegalArgumentException ("Method must be 'isTest' method"); } 44 45 48 private boolean isJUnitTest(IResource target) { 49 if (target != null) { 50 IJavaElement element = JavaCore.create(target); 51 if (element instanceof ICompilationUnit) { 52 ICompilationUnit cu = (ICompilationUnit) element; 53 IType mainType= cu.getType(Signature.getQualifier(cu.getElementName())); 54 try { 55 return TestSearchEngine.isTestOrTestSuite(mainType); 56 } catch (JavaModelException e) { 57 return false; 58 } 59 } 60 } 61 return false; 62 } 63 } 64 | Popular Tags |