1 8 package com.mountainminds.eclemma.internal.core.analysis; 9 10 import org.eclipse.core.resources.IResource; 11 import org.eclipse.jdt.core.IJavaElement; 12 import org.eclipse.jdt.core.IMethod; 13 import org.eclipse.jdt.core.IType; 14 import org.eclipse.jdt.core.Signature; 15 16 import com.mountainminds.eclemma.core.analysis.IJavaElementCoverage; 17 import com.mountainminds.eclemma.internal.core.DebugOptions; 18 import com.mountainminds.eclemma.internal.core.DebugOptions.ITracer; 19 20 26 public class TypeCoverage extends JavaElementCoverage implements ILazyBinding { 27 28 private static final ITracer TRACER = DebugOptions.ANALYSISTRACER; 29 30 public static class UnboundMethodCoverage { 31 final String name; 32 final String signature; 33 final IJavaElementCoverage coverage; 34 UnboundMethodCoverage(String name, String signature, IJavaElementCoverage coverage) { 35 this.name = name; 36 this.signature = signature; 37 this.coverage = coverage; 38 } 39 } 40 41 private UnboundMethodCoverage[] ubmethods; 42 43 public TypeCoverage(JavaElementCoverage parent, boolean haslines, long stamp) { 44 super(parent, haslines, stamp); 45 ubmethods = null; 46 } 47 48 public TypeCoverage(JavaElementCoverage parent, boolean haslines, IResource resource) { 49 super(parent, haslines, resource); 50 ubmethods = null; 51 } 52 53 54 public void setUnboundMethods(UnboundMethodCoverage[] ubmethods) { 55 this.ubmethods = ubmethods; 56 } 57 58 public void resolve(IJavaElement element, JavaModelCoverage modelcoverage) { 59 IType type = (IType) element; 60 if (ubmethods != null) { 61 for (int i = 0; i < ubmethods.length; i++) { 62 String name = ubmethods[i].name; 63 if (name.equals("<init>")) { name = type.getElementName(); 65 } 66 String [] paramtypes = Signature.getParameterTypes(ubmethods[i].signature); 67 for (int j = 0; j < paramtypes.length; j++) { 68 paramtypes[j] = paramtypes[j].replace('/', '.'); 69 } 70 IMethod pattern = type.getMethod(name, paramtypes); 71 IMethod[] hits = type.findMethods(pattern); 72 if (hits != null && hits.length == 1) { 73 modelcoverage.put(hits[0], ubmethods[i].coverage); 74 } else { 75 TRACER.trace("Method not found in Java model: {0}.{1}{2}", type.getElementName(), name, ubmethods[i].signature); } 77 } 78 ubmethods = null; 79 } 80 } 81 82 } 83 | Popular Tags |